aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Björklund <[email protected]>2021-04-19 20:03:57 +0200
committerLoïc Hoguin <[email protected]>2022-03-08 15:24:00 +0100
commit1ee2a1913e79e010733991d8373b2517abf0d91b (patch)
treef8c9d1876a3eb83d416d3d77bbf31053d6a0bec6
parent56cbf3823331a56474248541987c9b9d13c452d4 (diff)
downloadgun-1ee2a1913e79e010733991d8373b2517abf0d91b.tar.gz
gun-1ee2a1913e79e010733991d8373b2517abf0d91b.tar.bz2
gun-1ee2a1913e79e010733991d8373b2517abf0d91b.zip
Handle any zero-sized Data in http:data with fin
Amended to make the test case hit the problem.
-rw-r--r--src/gun_http.erl6
-rw-r--r--test/gun_SUITE.erl15
2 files changed, 18 insertions, 3 deletions
diff --git a/src/gun_http.erl b/src/gun_http.erl
index d928b18..b38cc74 100644
--- a/src/gun_http.erl
+++ b/src/gun_http.erl
@@ -692,10 +692,10 @@ data(State=#http_state{socket=Socket, transport=Transport, version=Version,
DataLength = iolist_size(Data),
case Out of
body_chunked when Version =:= 'HTTP/1.1', IsFin =:= fin ->
- case Data of
- <<>> ->
+ if
+ DataLength =:= 0 ->
Transport:send(Socket, cow_http_te:last_chunk());
- _ ->
+ true ->
Transport:send(Socket, [
cow_http_te:chunk(Data),
cow_http_te:last_chunk()
diff --git a/test/gun_SUITE.erl b/test/gun_SUITE.erl
index 1a15b01..ad39317 100644
--- a/test/gun_SUITE.erl
+++ b/test/gun_SUITE.erl
@@ -107,6 +107,21 @@ ignore_empty_data_http(_) ->
1 = length(Zero),
gun:close(Pid).
+ignore_empty_data_fin_http(_) ->
+ doc("When gun:data/4 is called with fin and empty data, it must send a final empty chunk."),
+ {ok, OriginPid, OriginPort} = init_origin(tcp, http),
+ {ok, Pid} = gun:open("localhost", OriginPort),
+ {ok, http} = gun:await_up(Pid),
+ handshake_completed = receive_from(OriginPid),
+ Ref = gun:post(Pid, "/", []),
+ gun:data(Pid, Ref, nofin, "hello"),
+ gun:data(Pid, Ref, fin, ["", <<>>]),
+ Data = receive_all_from(OriginPid, 500),
+ Lines = binary:split(Data, <<"\r\n">>, [global]),
+ Zero = [Z || <<"0">> = Z <- Lines],
+ 1 = length(Zero),
+ gun:close(Pid).
+
ignore_empty_data_http2(_) ->
doc("When gun:data/4 is called with nofin and empty data, it must be ignored."),
{ok, OriginPid, OriginPort} = init_origin(tcp, http2),