aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/http.hrl4
-rw-r--r--src/cowboy_protocol.erl2
-rw-r--r--src/cowboy_req.erl20
3 files changed, 10 insertions, 16 deletions
diff --git a/include/http.hrl b/include/http.hrl
index 5440d8f..e2a130b 100644
--- a/include/http.hrl
+++ b/include/http.hrl
@@ -39,8 +39,8 @@
meta = [] :: [{atom(), any()}],
%% Request body.
- body_state = waiting :: waiting | done | {stream, fun(), any(), fun()}
- | {multipart, non_neg_integer(), fun()},
+ body_state = waiting :: waiting | done | {stream, fun(), any(), fun()},
+ multipart = undefined :: undefined | {non_neg_integer(), fun()},
buffer = <<>> :: binary(),
%% Response.
diff --git a/src/cowboy_protocol.erl b/src/cowboy_protocol.erl
index 65012a5..2dd7ad0 100644
--- a/src/cowboy_protocol.erl
+++ b/src/cowboy_protocol.erl
@@ -424,7 +424,7 @@ ensure_body_processed(Req=#http_req{body_state=waiting}) ->
{ok, Req2} -> {ok, Req2#http_req.buffer};
{error, _Reason} -> {close, <<>>}
end;
-ensure_body_processed(Req=#http_req{body_state={multipart, _, _}}) ->
+ensure_body_processed(Req=#http_req{body_state={stream, _, _, _}}) ->
{ok, Req2} = cowboy_req:multipart_skip(Req),
ensure_body_processed(Req2).
diff --git a/src/cowboy_req.erl b/src/cowboy_req.erl
index fd1399d..e0804a6 100644
--- a/src/cowboy_req.erl
+++ b/src/cowboy_req.erl
@@ -490,13 +490,7 @@ stream_body(Req=#http_req{buffer=Buffer, body_state={stream, _, _, _}})
stream_body(Req=#http_req{body_state={stream, _, _, _}}) ->
stream_body_recv(Req);
stream_body(Req=#http_req{body_state=done}) ->
- {done, Req};
-stream_body(Req=#http_req{body_state={multipart, _N, _Fun},
- transport=Transport, socket=Socket}) ->
- case Transport:recv(Socket, 0, 5000) of
- {ok, Data} -> {ok, Data, Req};
- {error, Reason} -> {error, Reason}
- end.
+ {done, Req}.
-spec stream_body_recv(Req)
-> {ok, binary(), Req} | {error, atom()} when Req::req().
@@ -621,25 +615,25 @@ multipart_data(Req=#http_req{body_state=waiting}) ->
{_, Boundary} = lists:keyfind(<<"boundary">>, 1, Params),
{Length, Req3} = parse_header('Content-Length', Req2),
multipart_data(Req3, Length, {more, cowboy_multipart:parser(Boundary)});
-multipart_data(Req=#http_req{body_state={multipart, Length, Cont}}) ->
+multipart_data(Req=#http_req{multipart={Length, Cont}}) ->
multipart_data(Req, Length, Cont());
multipart_data(Req=#http_req{body_state=done}) ->
{eof, Req}.
%% @todo Typespecs.
multipart_data(Req, Length, {headers, Headers, Cont}) ->
- {{headers, Headers}, Req#http_req{body_state={multipart, Length, Cont}}};
+ {{headers, Headers}, Req#http_req{multipart={Length, Cont}}};
multipart_data(Req, Length, {body, Data, Cont}) ->
- {{body, Data}, Req#http_req{body_state={multipart, Length, Cont}}};
+ {{body, Data}, Req#http_req{multipart={Length, Cont}}};
multipart_data(Req, Length, {end_of_part, Cont}) ->
- {end_of_part, Req#http_req{body_state={multipart, Length, Cont}}};
+ {end_of_part, Req#http_req{multipart={Length, Cont}}};
multipart_data(Req, 0, eof) ->
- {eof, Req#http_req{body_state=done}};
+ {eof, Req#http_req{body_state=done, multipart=undefined}};
multipart_data(Req=#http_req{socket=Socket, transport=Transport},
Length, eof) ->
%% We just want to skip so no need to stream data here.
{ok, _Data} = Transport:recv(Socket, Length, 5000),
- {eof, Req#http_req{body_state=done}};
+ {eof, Req#http_req{body_state=done, multipart=undefined}};
multipart_data(Req, Length, {more, Parser}) when Length > 0 ->
case stream_body(Req) of
{ok, << Data:Length/binary, Buffer/binary >>, Req2} ->