aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_http2.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2016-06-13 16:00:17 +0200
committerLoïc Hoguin <[email protected]>2016-06-13 16:00:17 +0200
commitb82bb92f7e6cf751ec74fc8aec0bfea84bfc5415 (patch)
tree5a77cc01846d9c342bf3a6e8098bb401591f178d /src/cowboy_http2.erl
parent88227898edd26a823d0942fc7226adb61a20cb5d (diff)
downloadcowboy-b82bb92f7e6cf751ec74fc8aec0bfea84bfc5415.tar.gz
cowboy-b82bb92f7e6cf751ec74fc8aec0bfea84bfc5415.tar.bz2
cowboy-b82bb92f7e6cf751ec74fc8aec0bfea84bfc5415.zip
Fix streaming HTTP/2 responses
Error reporting for connection processes has been improved, using a similar proc_lib hack as was done for the stream processes.
Diffstat (limited to 'src/cowboy_http2.erl')
-rw-r--r--src/cowboy_http2.erl17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/cowboy_http2.erl b/src/cowboy_http2.erl
index c12e4f3..9be3715 100644
--- a/src/cowboy_http2.erl
+++ b/src/cowboy_http2.erl
@@ -385,6 +385,13 @@ commands(State=#state{socket=Socket, transport=Transport, encode_state=EncodeSta
]),
commands(State#state{encode_state=EncodeState}, StreamID, Tail)
end;
+%% Send response headers and initiate chunked encoding.
+commands(State=#state{socket=Socket, transport=Transport, encode_state=EncodeState0}, StreamID,
+ [{headers, StatusCode, Headers0}|Tail]) ->
+ Headers = Headers0#{<<":status">> => integer_to_binary(StatusCode)},
+ {HeaderBlock, EncodeState} = headers_encode(Headers, EncodeState0),
+ Transport:send(Socket, cow_http2:headers(StreamID, nofin, HeaderBlock)),
+ commands(State#state{encode_state=EncodeState}, StreamID, Tail);
%% Send a response body chunk.
%%
%% @todo WINDOW_UPDATE stuff require us to buffer some data.
@@ -455,7 +462,7 @@ commands(State, StreamID, [{upgrade, _Mod, _ModState}|Tail]) ->
commands(State, StreamID, Tail);
commands(State, StreamID, [stop|_Tail]) ->
%% @todo Do we want to run the commands after a stop?
- stream_terminate(State, StreamID, stop).
+ stream_terminate(State, StreamID, normal).
terminate(#state{socket=Socket, transport=Transport, handler=Handler,
streams=Streams, children=Children}, Reason) ->
@@ -550,8 +557,14 @@ stream_reset(State=#state{socket=Socket, transport=Transport}, StreamID,
Transport:send(Socket, cow_http2:rst_stream(StreamID, Reason)),
stream_terminate(State, StreamID, StreamError).
-stream_terminate(State=#state{handler=Handler, streams=Streams0, children=Children0}, StreamID, Reason) ->
+stream_terminate(State=#state{socket=Socket, transport=Transport,
+ handler=Handler, streams=Streams0, children=Children0}, StreamID, Reason) ->
case lists:keytake(StreamID, #stream.id, Streams0) of
+ {value, #stream{state=StreamState, local=nofin}, Streams} when Reason =:= normal ->
+ Transport:send(Socket, cow_http2:data(StreamID, fin, <<>>)),
+ stream_call_terminate(StreamID, Reason, Handler, StreamState),
+ Children = stream_terminate_children(Children0, StreamID, []),
+ State#state{streams=Streams, children=Children};
{value, #stream{state=StreamState}, Streams} ->
stream_call_terminate(StreamID, Reason, Handler, StreamState),
Children = stream_terminate_children(Children0, StreamID, []),