aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_http.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2011-12-01 20:38:38 +0100
committerLoïc Hoguin <[email protected]>2011-12-01 20:38:38 +0100
commit83ec63374f55e8cd407ba2cd6fc264acaa045422 (patch)
treef317eaa5d8ec67c8a5a63d8e11e41743ffb2ad11 /src/cowboy_http.erl
parent2ae5e804fb2262c95a5f87a00f72a2bd660501c1 (diff)
downloadcowboy-83ec63374f55e8cd407ba2cd6fc264acaa045422.tar.gz
cowboy-83ec63374f55e8cd407ba2cd6fc264acaa045422.tar.bz2
cowboy-83ec63374f55e8cd407ba2cd6fc264acaa045422.zip
Change the returned value for language_range parsing
Considering how it must be used, a simple binary is much better than a tag and a list of subtags. We still parse them like this to make sure they follow the specs, though.
Diffstat (limited to 'src/cowboy_http.erl')
-rw-r--r--src/cowboy_http.erl22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/cowboy_http.erl b/src/cowboy_http.erl
index 2dcee7e..4bb7c2c 100644
--- a/src/cowboy_http.erl
+++ b/src/cowboy_http.erl
@@ -236,7 +236,7 @@ language_tag(Data, Fun) ->
(<< $-, Rest/bits >>, Tag) ->
language_subtag(Rest, Fun, Tag, []);
(Rest, Tag) ->
- Fun(Rest, {Tag, []})
+ Fun(Rest, Tag)
end).
-spec language_subtag(binary(), fun(), binary(), [binary()]) -> any().
@@ -247,7 +247,9 @@ language_subtag(Data, Fun, Tag, Acc) ->
(<< $-, Rest/bits >>, SubTag) ->
language_subtag(Rest, Fun, Tag, [SubTag|Acc]);
(Rest, SubTag) ->
- Fun(Rest, {Tag, lists:reverse([SubTag|Acc])})
+ %% Rebuild the full tag now that we know it's correct
+ Sub = << << $-, S/binary >> || S <- lists:reverse([SubTag|Acc]) >>,
+ Fun(Rest, << Tag/binary, Sub/binary >>)
end).
-spec maybe_qparam(binary(), fun()) -> any().
@@ -687,16 +689,16 @@ nonempty_language_range_list_test_() ->
%% {Value, Result}
Tests = [
{<<"da, en-gb;q=0.8, en;q=0.7">>, [
- {{<<"da">>, []}, 1000},
- {{<<"en">>, [<<"gb">>]}, 800},
- {{<<"en">>, []}, 700}
+ {<<"da">>, 1000},
+ {<<"en-gb">>, 800},
+ {<<"en">>, 700}
]},
{<<"en, en-US, en-cockney, i-cherokee, x-pig-latin">>, [
- {{<<"en">>, []}, 1000},
- {{<<"en">>, [<<"us">>]}, 1000},
- {{<<"en">>, [<<"cockney">>]}, 1000},
- {{<<"i">>, [<<"cherokee">>]}, 1000},
- {{<<"x">>, [<<"pig">>, <<"latin">>]}, 1000}
+ {<<"en">>, 1000},
+ {<<"en-us">>, 1000},
+ {<<"en-cockney">>, 1000},
+ {<<"i-cherokee">>, 1000},
+ {<<"x-pig-latin">>, 1000}
]}
],
[{V, fun() -> R = nonempty_list(V, fun language_range/2) end}