diff options
author | Loïc Hoguin <[email protected]> | 2012-09-15 00:59:49 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2012-09-15 00:59:49 +0200 |
commit | 4040a9f72d080786f59533c398e2e5662087d92d (patch) | |
tree | 34dd4a041572ef84391d188a2d4ef5a0e7784d5a /src | |
parent | 79839b7bb5ae3aef77eb7ab704efa6168927845f (diff) | |
download | cowboy-4040a9f72d080786f59533c398e2e5662087d92d.tar.gz cowboy-4040a9f72d080786f59533c398e2e5662087d92d.tar.bz2 cowboy-4040a9f72d080786f59533c398e2e5662087d92d.zip |
Separate multipart from body_state
Diffstat (limited to 'src')
-rw-r--r-- | src/cowboy_protocol.erl | 2 | ||||
-rw-r--r-- | src/cowboy_req.erl | 20 |
2 files changed, 8 insertions, 14 deletions
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} -> |