aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnthony Ramine <[email protected]>2011-11-04 14:37:36 +0100
committerAnthony Ramine <[email protected]>2011-11-10 11:03:21 +0100
commit329b2fa01ef997e2cf723b5beb25c1feb9e74b16 (patch)
treece4d623ced79cc50d6431d918d25f5ebe5450d7e
parent2f27b046d71ed439e8a58e2f661e2a84a1d9bea4 (diff)
downloadcowboy-329b2fa01ef997e2cf723b5beb25c1feb9e74b16.tar.gz
cowboy-329b2fa01ef997e2cf723b5beb25c1feb9e74b16.tar.bz2
cowboy-329b2fa01ef997e2cf723b5beb25c1feb9e74b16.zip
Introduce cowboy_http:word/2
Used to parse either a token or a quoted string in parameters values.
-rw-r--r--src/cowboy_http.erl35
1 files changed, 15 insertions, 20 deletions
diff --git a/src/cowboy_http.erl b/src/cowboy_http.erl
index 6d14961..8f2d934 100644
--- a/src/cowboy_http.erl
+++ b/src/cowboy_http.erl
@@ -1,4 +1,5 @@
%% Copyright (c) 2011, Loïc Hoguin <[email protected]>
+%% Copyright (c) 2011, Anthony Ramine <[email protected]>
%%
%% Permission to use, copy, modify, and/or distribute this software for any
%% purpose with or without fee is hereby granted, provided that the above
@@ -106,19 +107,11 @@ media_range_param_value(Data, Fun, Type, SubType, Acc, <<"q">>) ->
fun (Rest, Quality) ->
accept_ext(Rest, Fun, Type, SubType, Acc, Quality, [])
end);
-media_range_param_value(Data = << $", _/bits >>, Fun,
- Type, SubType, Acc, Attr) ->
- quoted_string(Data,
+media_range_param_value(Data, Fun, Type, SubType, Acc, Attr) ->
+ word(Data,
fun (Rest, Value) ->
media_range_params(Rest, Fun,
Type, SubType, [{Attr, Value}|Acc])
- end);
-media_range_param_value(Data, Fun, Type, SubType, Acc, Attr) ->
- token(Data,
- fun (_Rest, <<>>) -> {error, badarg};
- (Rest, Value) ->
- media_range_params(Rest, Fun,
- Type, SubType, [{Attr, Value}|Acc])
end).
-spec accept_ext(binary(), fun(), binary(), binary(),
@@ -154,17 +147,9 @@ accept_ext_attr(Data, Fun, Type, SubType, Params, Quality, Acc) ->
-spec accept_ext_value(binary(), fun(), binary(), binary(),
[{binary(), binary()}], 0..1000,
[{binary(), binary()} | binary()], binary()) -> any().
-accept_ext_value(Data = << $", _/bits >>, Fun,
- Type, SubType, Params, Quality, Acc, Attr) ->
- quoted_string(Data,
- fun (Rest, Value) ->
- accept_ext(Rest, Fun,
- Type, SubType, Params, Quality, [{Attr, Value}|Acc])
- end);
accept_ext_value(Data, Fun, Type, SubType, Params, Quality, Acc, Attr) ->
- token(Data,
- fun (_Rest, <<>>) -> {error, badarg};
- (Rest, Value) ->
+ word(Data,
+ fun (Rest, Value) ->
accept_ext(Rest, Fun,
Type, SubType, Params, Quality, [{Attr, Value}|Acc])
end).
@@ -543,6 +528,16 @@ alpha(<< C, Rest/bits >>, Fun, Acc)
alpha(Data, Fun, Acc) ->
Fun(Data, Acc).
+%% @doc Parse either a token or a quoted string.
+-spec word(binary(), fun()) -> any().
+word(Data = << $", _/bits >>, Fun) ->
+ quoted_string(Data, Fun);
+word(Data, Fun) ->
+ token(Data,
+ fun (_Rest, <<>>) -> {error, badarg};
+ (Rest, Token) -> Fun(Rest, Token)
+ end).
+
%% @doc Parse a case-insensitive token.
%%
%% Changes all characters to lowercase.