0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-16 13:10:24 +00:00

Add chunked transfer encoding support and rework the body reading API

Introduces 3 low level functions and updates the existing higher
levels functions. The new primitives are has_body/1, body_length/1
and stream_body/1. In addition to that, a helper function
init_stream/4 has been added.

Streaming a body implies to decode the Transfer-Encoding and
Content-Encoding used for the body. By default, Cowboy will try
to figure out what was used and decode them properly. You can
override this if you want to disable this behavior or simply
support more encodings by calling the init_stream/4 function
before you start streaming the body.
This commit is contained in:
Loïc Hoguin 2012-03-29 01:14:44 +02:00
parent ba75e8b8ae
commit 95e05d822f
7 changed files with 311 additions and 39 deletions

View file

@ -396,10 +396,9 @@ next_request(Req=#http_req{connection=Conn},
ensure_body_processed(#http_req{body_state=done, buffer=Buffer}) ->
{ok, Buffer};
ensure_body_processed(Req=#http_req{body_state=waiting}) ->
case cowboy_http_req:body(Req) of
{error, badarg} -> {ok, Req#http_req.buffer}; %% No body.
{error, _Reason} -> {close, <<>>};
{ok, _, Req2} -> {ok, Req2#http_req.buffer}
case cowboy_http_req:skip_body(Req) of
{ok, Req2} -> {ok, Req2#http_req.buffer};
{error, _Reason} -> {close, <<>>}
end;
ensure_body_processed(Req=#http_req{body_state={multipart, _, _}}) ->
{ok, Req2} = cowboy_http_req:multipart_skip(Req),