aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_http_req.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2011-11-04 12:33:40 +0100
committerLoïc Hoguin <[email protected]>2011-11-04 12:33:40 +0100
commitaadd974f06ac1f089f7098c2ffe6f23d108f55be (patch)
treef6facccd30c85aa61fc1ed90e7fe3d8067e4dc58 /src/cowboy_http_req.erl
parenta118f53c74c71f42669d83f14b47a3b7a021e55d (diff)
parent04bcbc444d507f6936bfee18347ec292efe0ae67 (diff)
downloadcowboy-aadd974f06ac1f089f7098c2ffe6f23d108f55be.tar.gz
cowboy-aadd974f06ac1f089f7098c2ffe6f23d108f55be.tar.bz2
cowboy-aadd974f06ac1f089f7098c2ffe6f23d108f55be.zip
Merge branch 'parse_header-content-length' of https://github.com/nox/cowboy
Conflicts: src/cowboy_http.erl
Diffstat (limited to 'src/cowboy_http_req.erl')
-rw-r--r--src/cowboy_http_req.erl11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/cowboy_http_req.erl b/src/cowboy_http_req.erl
index 064722f..911aca1 100644
--- a/src/cowboy_http_req.erl
+++ b/src/cowboy_http_req.erl
@@ -231,6 +231,11 @@ parse_header(Name, Req, Default) when Name =:= 'Connection' ->
fun (Value) ->
cowboy_http:nonempty_list(Value, fun cowboy_http:token_ci/2)
end);
+parse_header(Name, Req, Default) when Name =:= 'Content-Length' ->
+ parse_header(Name, Req, Default,
+ fun (Value) ->
+ cowboy_http:digits(Value)
+ end);
parse_header(Name, Req, Default) ->
{Value, Req2} = header(Name, Req, Default),
{undefined, Value, Req2}.
@@ -292,12 +297,12 @@ cookies(Req=#http_req{cookies=Cookies}) ->
%% @todo We probably want to allow a max length.
-spec body(#http_req{}) -> {ok, binary(), #http_req{}} | {error, atom()}.
body(Req) ->
- {Length, Req2} = cowboy_http_req:header('Content-Length', Req),
+ {Length, Req2} = cowboy_http_req:parse_header('Content-Length', Req),
case Length of
undefined -> {error, badarg};
+ {error, badarg} -> {error, badarg};
_Any ->
- Length2 = list_to_integer(binary_to_list(Length)),
- body(Length2, Req2)
+ body(Length, Req2)
end.
%% @doc Return <em>Length</em> bytes of the request body.