mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-15 04:30:25 +00:00
Introduce cowboy_http:word/2
Used to parse either a token or a quoted string in parameters values.
This commit is contained in:
parent
2f27b046d7
commit
329b2fa01e
1 changed files with 15 additions and 20 deletions
|
@ -1,4 +1,5 @@
|
||||||
%% Copyright (c) 2011, Loïc Hoguin <essen@dev-extend.eu>
|
%% Copyright (c) 2011, Loïc Hoguin <essen@dev-extend.eu>
|
||||||
|
%% Copyright (c) 2011, Anthony Ramine <nox@dev-extend.eu>
|
||||||
%%
|
%%
|
||||||
%% Permission to use, copy, modify, and/or distribute this software for any
|
%% Permission to use, copy, modify, and/or distribute this software for any
|
||||||
%% purpose with or without fee is hereby granted, provided that the above
|
%% 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) ->
|
fun (Rest, Quality) ->
|
||||||
accept_ext(Rest, Fun, Type, SubType, Acc, Quality, [])
|
accept_ext(Rest, Fun, Type, SubType, Acc, Quality, [])
|
||||||
end);
|
end);
|
||||||
media_range_param_value(Data = << $", _/bits >>, Fun,
|
media_range_param_value(Data, Fun, Type, SubType, Acc, Attr) ->
|
||||||
Type, SubType, Acc, Attr) ->
|
word(Data,
|
||||||
quoted_string(Data,
|
|
||||||
fun (Rest, Value) ->
|
fun (Rest, Value) ->
|
||||||
media_range_params(Rest, Fun,
|
media_range_params(Rest, Fun,
|
||||||
Type, SubType, [{Attr, Value}|Acc])
|
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).
|
end).
|
||||||
|
|
||||||
-spec accept_ext(binary(), fun(), binary(), binary(),
|
-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(),
|
-spec accept_ext_value(binary(), fun(), binary(), binary(),
|
||||||
[{binary(), binary()}], 0..1000,
|
[{binary(), binary()}], 0..1000,
|
||||||
[{binary(), binary()} | binary()], binary()) -> any().
|
[{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) ->
|
accept_ext_value(Data, Fun, Type, SubType, Params, Quality, Acc, Attr) ->
|
||||||
token(Data,
|
word(Data,
|
||||||
fun (_Rest, <<>>) -> {error, badarg};
|
fun (Rest, Value) ->
|
||||||
(Rest, Value) ->
|
|
||||||
accept_ext(Rest, Fun,
|
accept_ext(Rest, Fun,
|
||||||
Type, SubType, Params, Quality, [{Attr, Value}|Acc])
|
Type, SubType, Params, Quality, [{Attr, Value}|Acc])
|
||||||
end).
|
end).
|
||||||
|
@ -543,6 +528,16 @@ alpha(<< C, Rest/bits >>, Fun, Acc)
|
||||||
alpha(Data, Fun, Acc) ->
|
alpha(Data, Fun, Acc) ->
|
||||||
Fun(Data, 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.
|
%% @doc Parse a case-insensitive token.
|
||||||
%%
|
%%
|
||||||
%% Changes all characters to lowercase.
|
%% Changes all characters to lowercase.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue