From b184b3588db5aab17b74269b9b81d640c559da4f Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Fri, 4 Nov 2011 15:07:00 +0100 Subject: Introduce cowboy_http:media_type/2 --- src/cowboy_http.erl | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'src/cowboy_http.erl') 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(). -- cgit v1.2.3