diff options
author | Loïc Hoguin <[email protected]> | 2014-04-26 14:38:24 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2014-04-26 14:38:24 +0200 |
commit | da29d8138dcc14c1b02b303c9b3da4a6135b985c (patch) | |
tree | fd6f96f8e5357f8d4794ef01ef08f1dd81007b6e /src | |
parent | 87cd5a220662eecaa5476da3c145f0617b73f734 (diff) | |
parent | 190938a75eb31981f37b4ef0ac4644df11f78419 (diff) | |
download | cowboy-da29d8138dcc14c1b02b303c9b3da4a6135b985c.tar.gz cowboy-da29d8138dcc14c1b02b303c9b3da4a6135b985c.tar.bz2 cowboy-da29d8138dcc14c1b02b303c9b3da4a6135b985c.zip |
Merge branch 'language-range-header' of git://github.com/NineFX/cowboy
Diffstat (limited to 'src')
-rw-r--r-- | src/cowboy_http.erl | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/cowboy_http.erl b/src/cowboy_http.erl index 754e74a..1cf73bf 100644 --- a/src/cowboy_http.erl +++ b/src/cowboy_http.erl @@ -241,7 +241,7 @@ language_tag(Data, Fun) -> -spec language_subtag(binary(), fun(), binary(), [binary()]) -> any(). language_subtag(Data, Fun, Tag, Acc) -> - alpha(Data, + alphanumeric(Data, fun (_Rest, SubTag) when byte_size(SubTag) =:= 0; byte_size(SubTag) > 8 -> {error, badarg}; (<< $-, Rest/binary >>, SubTag) -> @@ -615,6 +615,23 @@ alpha(<< C, Rest/binary >>, Fun, Acc) alpha(Data, Fun, Acc) -> Fun(Data, Acc). +-spec alphanumeric(binary(), fun()) -> any(). +alphanumeric(Data, Fun) -> + alphanumeric(Data, Fun, <<>>). + +-spec alphanumeric(binary(), fun(), binary()) -> any(). +alphanumeric(<<>>, Fun, Acc) -> + Fun(<<>>, Acc); +alphanumeric(<< C, Rest/binary >>, Fun, Acc) + when C >= $a andalso C =< $z; + C >= $A andalso C =< $Z; + C >= $0 andalso C =< $9 -> + C2 = cowboy_bstr:char_to_lower(C), + alphanumeric(Rest, Fun, << Acc/binary, C2 >>); +alphanumeric(Data, Fun, Acc) -> + Fun(Data, Acc). + +%% @doc Parse either a token or a quoted string. -spec word(binary(), fun()) -> any(). word(Data = << $", _/binary >>, Fun) -> quoted_string(Data, Fun); @@ -865,12 +882,13 @@ nonempty_language_range_list_test_() -> {<<"en-gb">>, 800}, {<<"en">>, 700} ]}, - {<<"en, en-US, en-cockney, i-cherokee, x-pig-latin">>, [ + {<<"en, en-US, en-cockney, i-cherokee, x-pig-latin, es-419">>, [ {<<"en">>, 1000}, {<<"en-us">>, 1000}, {<<"en-cockney">>, 1000}, {<<"i-cherokee">>, 1000}, - {<<"x-pig-latin">>, 1000} + {<<"x-pig-latin">>, 1000}, + {<<"es-419">>, 1000} ]} ], [{V, fun() -> R = nonempty_list(V, fun language_range/2) end} |