aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2013-02-14 18:35:53 +0100
committerLoïc Hoguin <[email protected]>2013-02-14 18:35:53 +0100
commit1df271a35bc98651dd94e2e774159dc61e283573 (patch)
tree34b3418eb25d5517d81aa7fb0a2dd63a32439ccf
parentbc340478c86340833c4c2def2a77f4828509c334 (diff)
parent1de2e1f2a45a82415a879910d7533498ecde8054 (diff)
downloadcowboy-1df271a35bc98651dd94e2e774159dc61e283573.tar.gz
cowboy-1df271a35bc98651dd94e2e774159dc61e283573.tar.bz2
cowboy-1df271a35bc98651dd94e2e774159dc61e283573.zip
Merge branch 'has_body_improved' of git://github.com/0xAX/cowboy
-rw-r--r--src/cowboy_req.erl10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/cowboy_req.erl b/src/cowboy_req.erl
index 0c4969d..8c9a618 100644
--- a/src/cowboy_req.erl
+++ b/src/cowboy_req.erl
@@ -564,8 +564,14 @@ set_meta(Name, Value, Req=#http_req{meta=Meta}) ->
%% @doc Return whether the request message has a body.
-spec has_body(cowboy_req:req()) -> boolean().
has_body(Req) ->
- lists:keymember(<<"content-length">>, 1, Req#http_req.headers) orelse
- lists:keymember(<<"transfer-encoding">>, 1, Req#http_req.headers).
+ case lists:keyfind(<<"content-length">>, 1, Req#http_req.headers) of
+ {_, <<"0">>} ->
+ false;
+ {_, _} ->
+ true;
+ _ ->
+ lists:keymember(<<"transfer-encoding">>, 1, Req#http_req.headers)
+ end.
%% @doc Return the request message body length, if known.
%%