aboutsummaryrefslogtreecommitdiffstats
path: root/src/gun_http.erl
diff options
context:
space:
mode:
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};