aboutsummaryrefslogtreecommitdiffstats
path: root/src/gun_http2.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2019-07-03 16:53:36 +0200
committerLoïc Hoguin <[email protected]>2019-07-03 16:53:36 +0200
commitd6b7ec654a876531dc0cfc7c65350d354bda2f52 (patch)
treea7f5e0eb9ff1647db963b204409f7d0bfe765ea7 /src/gun_http2.erl
parent4a6503186bf3a72880e7c99be76406550aeded96 (diff)
downloadgun-d6b7ec654a876531dc0cfc7c65350d354bda2f52.tar.gz
gun-d6b7ec654a876531dc0cfc7c65350d354bda2f52.tar.bz2
gun-d6b7ec654a876531dc0cfc7c65350d354bda2f52.zip
Add the response_start event
Thought it needed cow_http2_machine changes but everything was available. For HTTP/1.1 it is triggered when receiving data while expecting headers. For HTTP/2 it is triggered after we have received a HEADERS frame for streams in idle state.
Diffstat (limited to 'src/gun_http2.erl')
-rw-r--r--src/gun_http2.erl22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/gun_http2.erl b/src/gun_http2.erl
index 17bedde..4814818 100644
--- a/src/gun_http2.erl
+++ b/src/gun_http2.erl
@@ -113,7 +113,27 @@ parse(Data, State0=#http2_state{http2_machine=HTTP2Machine}, EvHandler, EvHandle
%% Frames received.
-frame(State=#http2_state{http2_machine=HTTP2Machine0}, Frame, EvHandler, EvHandlerState) ->
+frame(State=#http2_state{http2_machine=HTTP2Machine0}, Frame, EvHandler, EvHandlerState0) ->
+ EvHandlerState = if
+ is_tuple(Frame) andalso element(1, Frame) =:= headers ->
+ EvStreamID = element(2, Frame),
+ case cow_http2_machine:get_stream_remote_state(EvStreamID, HTTP2Machine0) of
+ {ok, idle} ->
+ #stream{ref=StreamRef, reply_to=ReplyTo} = get_stream_by_id(State, EvStreamID),
+ EvHandler:response_start(#{
+ stream_ref => StreamRef,
+ reply_to => ReplyTo
+ }, EvHandlerState0);
+ {ok, nofin} ->
+ %% @todo response_trailers.
+ EvHandlerState0;
+ %% This is an invalid headers frame.
+ _ ->
+ EvHandlerState0
+ end;
+ true ->
+ EvHandlerState0
+ end,
case cow_http2_machine:frame(Frame, HTTP2Machine0) of
{ok, HTTP2Machine} ->
{maybe_ack(State#http2_state{http2_machine=HTTP2Machine}, Frame),