aboutsummaryrefslogtreecommitdiffstats
path: root/src/gun_http.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_http.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_http.erl')
-rw-r--r--src/gun_http.erl14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/gun_http.erl b/src/gun_http.erl
index 7edaf14..b7c5bc1 100644
--- a/src/gun_http.erl
+++ b/src/gun_http.erl
@@ -100,7 +100,19 @@ handle(<<>>, State, _, EvHandlerState) ->
handle(_, #http_state{streams=[]}, _, EvHandlerState) ->
{close, EvHandlerState};
%% Wait for the full response headers before trying to parse them.
-handle(Data, State=#http_state{in=head, buffer=Buffer}, EvHandler, EvHandlerState) ->
+handle(Data, State=#http_state{in=head, buffer=Buffer,
+ streams=[#stream{ref=StreamRef, reply_to=ReplyTo}|_]}, EvHandler, EvHandlerState0) ->
+ %% Send the event only if there was no data in the buffer.
+ %% If there is data in the buffer then we already sent the event.
+ EvHandlerState = case Buffer of
+ <<>> ->
+ EvHandler:response_start(#{
+ stream_ref => StreamRef,
+ reply_to => ReplyTo
+ }, EvHandlerState0);
+ _ ->
+ EvHandlerState0
+ end,
Data2 = << Buffer/binary, Data/binary >>,
case binary:match(Data2, <<"\r\n\r\n">>) of
nomatch -> {{state, State#http_state{buffer=Data2}}, EvHandlerState};