aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2018-11-14 19:24:39 +0100
committerLoïc Hoguin <[email protected]>2018-11-14 19:24:39 +0100
commit292039362a6125dfd0a163d5b0a49b800bf80b11 (patch)
tree31a38f67960503ece6abfa82a0d285152d8dc4ff /src
parent4fedb336311604253153eafe81f33a77b44a0b2f (diff)
downloadcowboy-292039362a6125dfd0a163d5b0a49b800bf80b11.tar.gz
cowboy-292039362a6125dfd0a163d5b0a49b800bf80b11.tar.bz2
cowboy-292039362a6125dfd0a163d5b0a49b800bf80b11.zip
Don't send the content-length header in empty 304 responses
It's OK to send it when set explicitly, as it can be set to what the representation's size would have been.
Diffstat (limited to 'src')
-rw-r--r--src/cowboy_http.erl2
-rw-r--r--src/cowboy_req.erl8
2 files changed, 8 insertions, 2 deletions
diff --git a/src/cowboy_http.erl b/src/cowboy_http.erl
index caa4932..56a4af8 100644
--- a/src/cowboy_http.erl
+++ b/src/cowboy_http.erl
@@ -963,6 +963,8 @@ commands(State0=#state{socket=Socket, transport=Transport, streams=Streams0, out
{State1, Headers1} = case {Status, ContentLength, Version} of
{204, _, 'HTTP/1.1'} ->
{State0#state{out_state=done}, Headers0};
+ {304, _, 'HTTP/1.1'} ->
+ {State0#state{out_state=done}, Headers0};
{_, undefined, 'HTTP/1.1'} ->
{State0#state{out_state=chunked}, Headers0#{<<"transfer-encoding">> => <<"chunked">>}};
%% Close the connection after streaming without content-length to HTTP/1.0 client.
diff --git a/src/cowboy_req.erl b/src/cowboy_req.erl
index 2c3de06..5633182 100644
--- a/src/cowboy_req.erl
+++ b/src/cowboy_req.erl
@@ -771,11 +771,15 @@ reply(Status, Headers, SendFile = {sendfile, _, Len, _}, Req)
do_reply(Status, Headers#{
<<"content-length">> => integer_to_binary(Len)
}, SendFile, Req);
-%% 204 responses must not include content-length. (RFC7230 3.3.1, RFC7230 3.3.2)
-reply(Status=204, Headers, Body, Req) ->
+%% 204 responses must not include content-length. 304 responses may
+%% but only when set explicitly. (RFC7230 3.3.1, RFC7230 3.3.2)
+reply(Status, Headers, Body, Req)
+ when Status =:= 204; Status =:= 304 ->
do_reply(Status, Headers, Body, Req);
reply(Status= <<"204",_/bits>>, Headers, Body, Req) ->
do_reply(Status, Headers, Body, Req);
+reply(Status= <<"304",_/bits>>, Headers, Body, Req) ->
+ do_reply(Status, Headers, Body, Req);
reply(Status, Headers, Body, Req)
when is_integer(Status); is_binary(Status) ->
do_reply(Status, Headers#{