aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2015-02-16 19:49:01 +0100
committerLoïc Hoguin <[email protected]>2015-02-16 19:49:01 +0100
commitd2205d9ea6aa71ff256c48667755676d0e6c2377 (patch)
tree1a3aeeafa833da3d1fcbfb67af6224ce077c5e23 /src
parent8d2063bb2ea8fec3f1807cd8181cbe25689838f1 (diff)
downloadcowboy-d2205d9ea6aa71ff256c48667755676d0e6c2377.tar.gz
cowboy-d2205d9ea6aa71ff256c48667755676d0e6c2377.tar.bz2
cowboy-d2205d9ea6aa71ff256c48667755676d0e6c2377.zip
Do not send empty chunks
User code may sometimes send an empty value which gets understood by the client as being the end of the stream while this was not intended. Ignoring empty values allow making sure the stream isn't ended by mistake.
Diffstat (limited to 'src')
-rw-r--r--src/cowboy_req.erl7
1 files changed, 5 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().