diff options
author | Anthony Ramine <[email protected]> | 2011-11-04 15:07:00 +0100 |
---|---|---|
committer | Anthony Ramine <[email protected]> | 2011-11-10 11:03:22 +0100 |
commit | b184b3588db5aab17b74269b9b81d640c559da4f (patch) | |
tree | 833240678efe4aa7b9f998011d7fc0ee01925f4d /src | |
parent | 329b2fa01ef997e2cf723b5beb25c1feb9e74b16 (diff) | |
download | cowboy-b184b3588db5aab17b74269b9b81d640c559da4f.tar.gz cowboy-b184b3588db5aab17b74269b9b81d640c559da4f.tar.bz2 cowboy-b184b3588db5aab17b74269b9b81d640c559da4f.zip |
Introduce cowboy_http:media_type/2
Diffstat (limited to 'src')
-rw-r--r-- | src/cowboy_http.erl | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/cowboy_http.erl b/src/cowboy_http.erl index 8f2d934..9aeaafe 100644 --- a/src/cowboy_http.erl +++ b/src/cowboy_http.erl @@ -70,13 +70,9 @@ list(Data, Fun, Acc) -> %% @doc Parse a media range. -spec media_range(binary(), fun()) -> any(). media_range(Data, Fun) -> - token_ci(Data, - fun (_Rest, <<>>) -> {error, badarg}; - (<< $/, Rest/bits >>, Type) -> token_ci(Rest, - fun (_Rest2, <<>>) -> {error, badarg}; - (Rest2, SubType) -> - media_range_params(Rest2, Fun, Type, SubType, []) - end) + media_type(Data, + fun (Rest, Type, SubType) -> + media_range_params(Rest, Fun, Type, SubType, []) end). -spec media_range_params(binary(), fun(), binary(), binary(), @@ -114,6 +110,19 @@ media_range_param_value(Data, Fun, Type, SubType, Acc, Attr) -> Type, SubType, [{Attr, Value}|Acc]) end). +%% @doc Parse a media type. +-spec media_type(binary(), fun()) -> any(). +media_type(Data, Fun) -> + token_ci(Data, + fun (_Rest, <<>>) -> {error, badarg}; + (<< $/, Rest/bits >>, Type) -> + token_ci(Rest, + fun (_Rest2, <<>>) -> {error, badarg}; + (Rest2, SubType) -> Fun(Rest2, Type, SubType) + end); + (_Rest, _Type) -> {error, badarg} + end). + -spec accept_ext(binary(), fun(), binary(), binary(), [{binary(), binary()}], 0..1000, [{binary(), binary()} | binary()]) -> any(). |