aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gun_http.erl10
-rw-r--r--test/gun_SUITE.erl26
2 files changed, 31 insertions, 5 deletions
diff --git a/src/gun_http.erl b/src/gun_http.erl
index e6b597c..376f431 100644
--- a/src/gun_http.erl
+++ b/src/gun_http.erl
@@ -142,7 +142,7 @@ handle(Data, State=#http_state{in=body_chunked, in_state=InState,
{no_trailers, keepalive} ->
handle(Rest, end_stream(State1#http_state{buffer= <<>>}));
{no_trailers, close} ->
- close
+ [{state, end_stream(State1)}, close]
end;
{done, Data2, HasTrailers, Rest} ->
IsFin = case HasTrailers of
@@ -156,7 +156,7 @@ handle(Data, State=#http_state{in=body_chunked, in_state=InState,
{no_trailers, keepalive} ->
handle(Rest, end_stream(State1#http_state{buffer= <<>>}));
{no_trailers, close} ->
- close
+ [{state, end_stream(State1)}, close]
end
end;
handle(Data, State=#http_state{in=body_trailer, buffer=Buffer, connection=Conn,
@@ -172,7 +172,7 @@ handle(Data, State=#http_state{in=body_trailer, buffer=Buffer, connection=Conn,
keepalive ->
handle(Rest, end_stream(State#http_state{buffer= <<>>}));
close ->
- close
+ [{state, end_stream(State)}, close]
end
end;
%% We know the length of the rest of the body.
@@ -189,7 +189,7 @@ handle(Data, State=#http_state{in={body, Length}, connection=Conn}) ->
State1 = send_data_if_alive(Data, State, fin),
case Conn of
keepalive -> {state, end_stream(State1)};
- close -> close
+ close -> [{state, end_stream(State1)}, close]
end;
%% Stream finished, rest.
true ->
@@ -197,7 +197,7 @@ handle(Data, State=#http_state{in={body, Length}, connection=Conn}) ->
State1 = send_data_if_alive(Body, State, fin),
case Conn of
keepalive -> handle(Rest, end_stream(State1));
- close -> close
+ close -> [{state, end_stream(State1)}, close]
end
end.
diff --git a/test/gun_SUITE.erl b/test/gun_SUITE.erl
index 93a09cc..6da5ca6 100644
--- a/test/gun_SUITE.erl
+++ b/test/gun_SUITE.erl
@@ -180,6 +180,32 @@ keepalive_infinity(_) ->
error(timeout)
end.
+killed_streams_http(_) ->
+ doc("Ensure completed responses with a connection: close are not considered killed streams."),
+ {ok, _, OriginPort} = init_origin(tcp, http,
+ fun (_, ClientSocket, ClientTransport) ->
+ {ok, _} = ClientTransport:recv(ClientSocket, 0, 1000),
+ ClientTransport:send(ClientSocket,
+ "HTTP/1.1 200 OK\r\n"
+ "connection: close\r\n"
+ "content-length: 12\r\n"
+ "\r\n"
+ "hello world!"
+ )
+ end),
+ {ok, ConnPid} = gun:open("localhost", OriginPort),
+ {ok, http} = gun:await_up(ConnPid),
+ StreamRef = gun:get(ConnPid, "/"),
+ {response, nofin, 200, _} = gun:await(ConnPid, StreamRef),
+ {ok, <<"hello world!">>} = gun:await_body(ConnPid, StreamRef),
+ receive
+ {gun_down, ConnPid, http, normal, KilledStreams, _} ->
+ [] = KilledStreams,
+ gun:close(ConnPid)
+ after 1000 ->
+ error(timeout)
+ end.
+
reply_to(_) ->
doc("The reply_to option allows using a separate process for requests."),
do_reply_to(http),