From d4ce3c638de136484fe21b85ea7c15eff055cee3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Mon, 24 Mar 2014 14:14:43 +0100 Subject: Use the new chunked and identity transfer decoding code from cowlib --- src/cowboy_req.erl | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'src/cowboy_req.erl') diff --git a/src/cowboy_req.erl b/src/cowboy_req.erl index 552c3ba..56f55e0 100644 --- a/src/cowboy_req.erl +++ b/src/cowboy_req.erl @@ -632,7 +632,7 @@ stream_body(MaxLength, Req=#http_req{body_state=waiting, version=Version, {ok, [<<"chunked">>], Req2} -> stream_body(MaxLength, Req2#http_req{body_state= {stream, 0, - fun cowboy_http:te_chunked/2, {0, 0}, + fun cow_http_te:stream_chunked/2, {0, 0}, fun cowboy_http:ce_identity/1}}); {ok, [<<"identity">>], Req2} -> {Length, Req3} = body_length(Req2), @@ -642,7 +642,7 @@ stream_body(MaxLength, Req=#http_req{body_state=waiting, version=Version, Length -> stream_body(MaxLength, Req3#http_req{body_state= {stream, Length, - fun cowboy_http:te_identity/2, {0, Length}, + fun cow_http_te:stream_identity/2, {0, Length}, fun cowboy_http:ce_identity/1}}) end end; @@ -666,31 +666,34 @@ stream_body_recv(MaxLength, Req=#http_req{ {error, Reason} -> {error, Reason} end. +%% @todo Handle chunked after-the-facts headers. +%% @todo Depending on the length returned we might want to 0 or +5 it. -spec transfer_decode(binary(), Req) -> {ok, binary(), Req} | {error, atom()} when Req::req(). transfer_decode(Data, Req=#http_req{body_state={stream, _, TransferDecode, TransferState, ContentDecode}}) -> case TransferDecode(Data, TransferState) of - {ok, Data2, Rest, TransferState2} -> - content_decode(ContentDecode, Data2, - Req#http_req{buffer=Rest, body_state={stream, 0, - TransferDecode, TransferState2, ContentDecode}}); - %% @todo {header(s) for chunked more -> stream_body_recv(0, Req#http_req{buffer=Data, body_state={stream, 0, TransferDecode, TransferState, ContentDecode}}); - {more, Length, Data2, TransferState2} -> + {more, Data2, TransferState2} -> + content_decode(ContentDecode, Data2, + Req#http_req{body_state={stream, 0, + TransferDecode, TransferState2, ContentDecode}}); + {more, Data2, Length, TransferState2} -> content_decode(ContentDecode, Data2, Req#http_req{body_state={stream, Length, TransferDecode, TransferState2, ContentDecode}}); + {more, Data2, Length, Rest, TransferState2} -> + content_decode(ContentDecode, Data2, + Req#http_req{buffer=Rest, body_state={stream, Length, + TransferDecode, TransferState2, ContentDecode}}); {done, Length, Rest} -> Req2 = transfer_decode_done(Length, Rest, Req), {done, Req2}; {done, Data2, Length, Rest} -> Req2 = transfer_decode_done(Length, Rest, Req), - content_decode(ContentDecode, Data2, Req2); - {error, Reason} -> - {error, Reason} + content_decode(ContentDecode, Data2, Req2) end. -spec transfer_decode_done(non_neg_integer(), binary(), Req) -- cgit v1.2.3