aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/cowboy_req.erl7
-rw-r--r--test/http_SUITE_data/http_chunked.erl2
2 files changed, 7 insertions, 2 deletions
diff --git a/src/cowboy_req.erl b/src/cowboy_req.erl
index 5e23a7b..feac388 100644
--- a/src/cowboy_req.erl
+++ b/src/cowboy_req.erl
@@ -823,8 +823,11 @@ chunk(Data, #http_req{socket=Socket, transport=Transport,
ok = Transport:send(Socket, Data);
chunk(Data, #http_req{socket=Socket, transport=Transport,
resp_state=chunks}) ->
- ok = Transport:send(Socket, [integer_to_list(iolist_size(Data), 16),
- <<"\r\n">>, Data, <<"\r\n">>]).
+ case iolist_size(Data) of
+ 0 -> ok;
+ Size -> Transport:send(Socket, [integer_to_list(Size, 16),
+ <<"\r\n">>, Data, <<"\r\n">>])
+ end.
%% If ever made public, need to send nothing if HEAD.
-spec last_chunk(Req) -> Req when Req::req().
diff --git a/test/http_SUITE_data/http_chunked.erl b/test/http_SUITE_data/http_chunked.erl
index 87a6852..6433f66 100644
--- a/test/http_SUITE_data/http_chunked.erl
+++ b/test/http_SUITE_data/http_chunked.erl
@@ -6,6 +6,8 @@
init(Req, Opts) ->
Req2 = cowboy_req:chunked_reply(200, Req),
+ %% Try an empty chunk to make sure the stream doesn't get closed.
+ cowboy_req:chunk([<<>>], Req2),
timer:sleep(100),
cowboy_req:chunk("chunked_handler\r\n", Req2),
timer:sleep(100),