aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2017-09-04 20:48:07 +0200
committerLoïc Hoguin <[email protected]>2017-09-04 20:48:07 +0200
commit4fd6e2f7cdca1c1adf1ba0bd76a0702328c380f4 (patch)
treeb644857e9b4134f2db67b936b29fa2456af48dfb /src
parent0995fc99e039ea0b6b2979801c2ab1e0eb05a910 (diff)
downloadcowboy-4fd6e2f7cdca1c1adf1ba0bd76a0702328c380f4.tar.gz
cowboy-4fd6e2f7cdca1c1adf1ba0bd76a0702328c380f4.tar.bz2
cowboy-4fd6e2f7cdca1c1adf1ba0bd76a0702328c380f4.zip
Accept sendfile tuple with 0 length in cowboy_req
This will result in no data being sent. It's simply easier to do this than to have to handle 0 size cases in user code.
Diffstat (limited to 'src')
-rw-r--r--src/cowboy_req.erl7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/cowboy_req.erl b/src/cowboy_req.erl
index 09e1ee5..936f6bb 100644
--- a/src/cowboy_req.erl
+++ b/src/cowboy_req.erl
@@ -98,7 +98,7 @@
%% Cowboy expects the real length as it is used as metadata.
%% @todo We should probably explicitly reject it.
-type resp_body() :: iodata()
- | {sendfile, non_neg_integer(), pos_integer(), file:name_all()}.
+ | {sendfile, non_neg_integer(), non_neg_integer(), file:name_all()}.
-export_type([resp_body/0]).
-type push_opts() :: #{
@@ -635,6 +635,11 @@ reply(Status, Headers, Req) ->
-> Req when Req::req().
reply(_, _, _, #{has_sent_resp := _}) ->
error(function_clause);
+reply(Status, Headers, Sendfile = {sendfile, _, 0, _}, Req)
+ when is_integer(Status); is_binary(Status) ->
+ do_reply(Status, Headers#{
+ <<"content-length">> => <<"0">>
+ }, <<>>, Req);
reply(Status, Headers, SendFile = {sendfile, _, Len, _}, Req)
when is_integer(Status); is_binary(Status) ->
do_reply(Status, Headers#{