aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/cowboy_http.erl2
-rw-r--r--test/req_SUITE.erl14
2 files changed, 10 insertions, 6 deletions
diff --git a/src/cowboy_http.erl b/src/cowboy_http.erl
index 5b07a4c..5136a3b 100644
--- a/src/cowboy_http.erl
+++ b/src/cowboy_http.erl
@@ -1215,7 +1215,7 @@ stream_terminate(State0=#state{opts=Opts, in_streamid=InStreamID, in_state=InSta
info(State0, StreamID, {response, 204, #{}, <<>>});
chunked when Version =:= 'HTTP/1.1' ->
info(State0, StreamID, {data, fin, <<>>});
- streaming when ExpectedSize < SentSize ->
+ streaming when SentSize < ExpectedSize ->
terminate(State0, response_body_too_small);
_ -> %% done or Version =:= 'HTTP/1.0'
State0
diff --git a/test/req_SUITE.erl b/test/req_SUITE.erl
index c79dbf6..cb54167 100644
--- a/test/req_SUITE.erl
+++ b/test/req_SUITE.erl
@@ -151,7 +151,6 @@ do_get_error(Path, Headers, Config) ->
nofin -> gun:await_body(ConnPid, Ref);
fin -> {ok, <<>>}
end,
- gun:close(ConnPid),
case Result of
{ok, RespBody} -> {Status, RespHeaders, do_decode(RespHeaders, RespBody)};
_ -> Result
@@ -953,16 +952,21 @@ stream_body_content_length_nofin(Config) ->
ok.
stream_body_content_length_nofin_error(Config) ->
- doc("Not all of body sent."),
+ doc("Not all of the response body sent."),
case config(protocol, Config) of
http ->
case do_get_error("/resp/stream_body_content_length/nofin-error", Config) of
+ %% When compression is used content-length is not sent.
{200, Headers, <<"Hello">>} ->
{_, <<"gzip">>} = lists:keyfind(<<"content-encoding">>, 1, Headers);
+ %% The server closes the connection when the body couldn't be sent fully.
{error, {stream_error, closed}} ->
- ok;
- {error, timeout} ->
- ok
+ receive
+ {gun_down, ConnPid, _, _, _, _} ->
+ gun:close(ConnPid)
+ after 1000 ->
+ error(timeout)
+ end
end;
http2 ->
%% @todo HTTP2 should have the same content-length checks