aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2016-06-08 23:09:14 +0200
committerLoïc Hoguin <[email protected]>2016-06-08 23:09:14 +0200
commit1470f8831988845efa07091e452cd0bede09d7b6 (patch)
tree23c98d6b7f0ff0c4a6486242870b04efaf28bb2f
parent98323c2d72ffa0a164d525b39290125a6ab3b070 (diff)
downloadcowboy-1470f8831988845efa07091e452cd0bede09d7b6.tar.gz
cowboy-1470f8831988845efa07091e452cd0bede09d7b6.tar.bz2
cowboy-1470f8831988845efa07091e452cd0bede09d7b6.zip
Fix request body reading in HTTP/2
-rw-r--r--src/cowboy_http2.erl17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/cowboy_http2.erl b/src/cowboy_http2.erl
index 94581ac..c12e4f3 100644
--- a/src/cowboy_http2.erl
+++ b/src/cowboy_http2.erl
@@ -28,7 +28,9 @@
%% Whether we finished sending data.
local = nofin :: cowboy_stream:fin(),
%% Whether we finished receiving data.
- remote = nofin :: cowboy_stream:fin()
+ remote = nofin :: cowboy_stream:fin(),
+ %% Request body length.
+ body_length = 0 :: non_neg_integer()
}).
-type stream() :: #stream{}.
@@ -233,17 +235,22 @@ parse_settings_preface(State, _, _, _) ->
%% and terminate the stream if this is the end of it.
%% DATA frame.
-frame(State=#state{handler=Handler, streams=Streams0}, {data, StreamID, IsFin, Data}) ->
+frame(State=#state{handler=Handler, streams=Streams0}, {data, StreamID, IsFin0, Data}) ->
case lists:keyfind(StreamID, #stream.id, Streams0) of
- Stream = #stream{state=StreamState0, remote=nofin} ->
+ Stream = #stream{state=StreamState0, remote=nofin, body_length=Len0} ->
+ Len = Len0 + byte_size(Data),
+ IsFin = case IsFin0 of
+ fin -> {fin, Len};
+ nofin -> nofin
+ end,
try Handler:data(StreamID, IsFin, Data, StreamState0) of
{Commands, StreamState} ->
Streams = lists:keyreplace(StreamID, #stream.id, Streams0,
- Stream#stream{state=StreamState}),
+ Stream#stream{state=StreamState, body_length=Len}),
commands(State#state{streams=Streams}, StreamID, Commands)
catch Class:Reason ->
error_logger:error_msg("Exception occurred in ~s:data(~p, ~p, ~p, ~p) with reason ~p:~p.",
- [Handler, StreamID, IsFin, Data, StreamState0, Class, Reason]),
+ [Handler, StreamID, IsFin0, Data, StreamState0, Class, Reason]),
stream_reset(State, StreamID, {internal_error, {Class, Reason},
'Exception occurred in StreamHandler:data/4 call.'})
end;