aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cowboy_http.erl78
-rw-r--r--src/cowboy_http_req.erl5
-rw-r--r--src/cowboy_http_rest.erl2
-rw-r--r--src/cowboy_multipart.erl6
-rw-r--r--src/cowboy_ssl_transport.erl9
5 files changed, 62 insertions, 38 deletions
diff --git a/src/cowboy_http.erl b/src/cowboy_http.erl
index 32b0ca9..6c5a6ea 100644
--- a/src/cowboy_http.erl
+++ b/src/cowboy_http.erl
@@ -17,8 +17,8 @@
-module(cowboy_http).
%% Parsing.
--export([list/2, nonempty_list/2, content_type/1, content_type_params/3,
- media_range/2, conneg/2, language_range/2, entity_tag_match/1,
+-export([list/2, nonempty_list/2, content_type/1, media_range/2, conneg/2,
+ language_range/2, entity_tag_match/1, expectation/2, params/2,
http_date/1, rfc1123_date/1, rfc850_date/1, asctime_date/1,
whitespace/2, digits/1, token/2, token_ci/2, quoted_string/2]).
@@ -98,33 +98,9 @@ list(Data, Fun, Acc) ->
content_type(Data) ->
media_type(Data,
fun (Rest, Type, SubType) ->
- content_type_params(Rest,
- fun (Params) -> {Type, SubType, Params} end, [])
- end).
-
--spec content_type_params(binary(), fun(), list({binary(), binary()}))
- -> any().
-content_type_params(Data, Fun, Acc) ->
- whitespace(Data,
- fun (<< $;, Rest/binary >>) -> content_type_param(Rest, Fun, Acc);
- (<<>>) -> Fun(lists:reverse(Acc));
- (_Rest) -> {error, badarg}
- end).
-
--spec content_type_param(binary(), fun(), list({binary(), binary()}))
- -> any().
-content_type_param(Data, Fun, Acc) ->
- whitespace(Data,
- fun (Rest) ->
- token_ci(Rest,
- fun (_Rest2, <<>>) -> {error, badarg};
- (<< $=, Rest2/binary >>, Attr) ->
- word(Rest2,
- fun (Rest3, Value) ->
- content_type_params(Rest3, Fun,
- [{Attr, Value}|Acc])
- end);
- (_Rest2, _Attr) -> {error, badarg}
+ params(Rest,
+ fun (<<>>, Params) -> {Type, SubType, Params};
+ (_Rest2, _) -> {error, badarg}
end)
end).
@@ -319,6 +295,50 @@ opaque_tag(Data, Fun, Strength) ->
(Rest, OpaqueTag) -> Fun(Rest, {Strength, OpaqueTag})
end).
+%% @doc Parse an expectation.
+-spec expectation(binary(), fun()) -> any().
+expectation(Data, Fun) ->
+ token_ci(Data,
+ fun (_Rest, <<>>) -> {error, badarg};
+ (<< $=, Rest/binary >>, Expectation) ->
+ word(Rest,
+ fun (Rest2, ExtValue) ->
+ params(Rest2, fun (Rest3, ExtParams) ->
+ Fun(Rest3, {Expectation, ExtValue, ExtParams})
+ end)
+ end);
+ (Rest, Expectation) ->
+ Fun(Rest, Expectation)
+ end).
+
+%% @doc Parse a list of parameters (a=b;c=d).
+-spec params(binary(), fun()) -> any().
+params(Data, Fun) ->
+ params(Data, Fun, []).
+
+-spec params(binary(), fun(), [{binary(), binary()}]) -> any().
+params(Data, Fun, Acc) ->
+ whitespace(Data,
+ fun (<< $;, Rest/binary >>) -> param(Rest, Fun, Acc);
+ (Rest) -> Fun(Rest, lists:reverse(Acc))
+ end).
+
+-spec param(binary(), fun(), [{binary(), binary()}]) -> any().
+param(Data, Fun, Acc) ->
+ whitespace(Data,
+ fun (Rest) ->
+ token_ci(Rest,
+ fun (_Rest2, <<>>) -> {error, badarg};
+ (<< $=, Rest2/binary >>, Attr) ->
+ word(Rest2,
+ fun (Rest3, Value) ->
+ params(Rest3, Fun,
+ [{Attr, Value}|Acc])
+ end);
+ (_Rest2, _Attr) -> {error, badarg}
+ end)
+ end).
+
%% @doc Parse an HTTP date (RFC1123, RFC850 or asctime date).
%% @end
%%
diff --git a/src/cowboy_http_req.erl b/src/cowboy_http_req.erl
index 92d96ad..e3efd2b 100644
--- a/src/cowboy_http_req.erl
+++ b/src/cowboy_http_req.erl
@@ -271,6 +271,11 @@ parse_header(Name, Req, Default) when Name =:= 'Content-Type' ->
fun (Value) ->
cowboy_http:content_type(Value)
end);
+parse_header(Name, Req, Default) when Name =:= 'Expect' ->
+ parse_header(Name, Req, Default,
+ fun (Value) ->
+ cowboy_http:nonempty_list(Value, fun cowboy_http:expectation/2)
+ end);
parse_header(Name, Req, Default)
when Name =:= 'If-Match'; Name =:= 'If-None-Match' ->
parse_header(Name, Req, Default,
diff --git a/src/cowboy_http_rest.erl b/src/cowboy_http_rest.erl
index 392b172..8f14388 100644
--- a/src/cowboy_http_rest.erl
+++ b/src/cowboy_http_rest.erl
@@ -699,7 +699,7 @@ process_post(Req, State) ->
terminate(Req2, State#state{handler_state=HandlerState});
{true, Req2, HandlerState} ->
State2 = State#state{handler_state=HandlerState},
- next(Req2, State2, 201);
+ next(Req2, State2, fun is_new_resource/2);
{false, Req2, HandlerState} ->
State2 = State#state{handler_state=HandlerState},
respond(Req2, State2, 500)
diff --git a/src/cowboy_multipart.erl b/src/cowboy_multipart.erl
index b7aeb54..2428b52 100644
--- a/src/cowboy_multipart.erl
+++ b/src/cowboy_multipart.erl
@@ -45,8 +45,10 @@ content_disposition(Data) ->
cowboy_http:token_ci(Data,
fun (_Rest, <<>>) -> {error, badarg};
(Rest, Disposition) ->
- cowboy_http:content_type_params(Rest,
- fun (Params) -> {Disposition, Params} end, [])
+ cowboy_http:params(Rest,
+ fun (<<>>, Params) -> {Disposition, Params};
+ (_Rest2, _) -> {error, badarg}
+ end)
end).
%% Internal.
diff --git a/src/cowboy_ssl_transport.erl b/src/cowboy_ssl_transport.erl
index b7d555b..8eaf320 100644
--- a/src/cowboy_ssl_transport.erl
+++ b/src/cowboy_ssl_transport.erl
@@ -68,17 +68,16 @@ listen(Opts) ->
{port, Port} = lists:keyfind(port, 1, Opts),
Backlog = proplists:get_value(backlog, Opts, 1024),
{certfile, CertFile} = lists:keyfind(certfile, 1, Opts),
- KeyFileOpts =
+ KeyFileOpts =
case lists:keyfind(keyfile, 1, Opts) of
false -> [];
KeyFile -> [KeyFile]
end,
- PasswordOpts =
+ PasswordOpts =
case lists:keyfind(password, 1, Opts) of
false -> [];
Password -> [Password]
end,
-
ListenOpts0 = [binary, {active, false},
{backlog, Backlog}, {packet, raw}, {reuseaddr, true},
{certfile, CertFile}],
@@ -92,9 +91,7 @@ listen(Opts) ->
false -> ListenOpts1;
CACertFile -> [CACertFile|ListenOpts1]
end,
-
- ListenOpts = ListenOpts2 ++ KeyFileOpts ++ PasswordOpts,
-
+ ListenOpts = ListenOpts2 ++ KeyFileOpts ++ PasswordOpts,
ssl:listen(Port, ListenOpts).
%% @doc Accept an incoming connection on a listen socket.