mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 12:20:24 +00:00
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.
This commit is contained in:
parent
4fedb33631
commit
292039362a
4 changed files with 74 additions and 5 deletions
|
@ -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#{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue