aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_http_req.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2011-03-21 21:28:24 +0100
committerLoïc Hoguin <[email protected]>2011-03-21 22:08:27 +0100
commit7cacb88fecc2d64609168167303aaca00181ee53 (patch)
tree6b473fbec2429475e8489756bdd097789614f351 /src/cowboy_http_req.erl
parente9781e77f15a8bfa339d53cf6207a2453cb4c322 (diff)
downloadcowboy-7cacb88fecc2d64609168167303aaca00181ee53.tar.gz
cowboy-7cacb88fecc2d64609168167303aaca00181ee53.tar.bz2
cowboy-7cacb88fecc2d64609168167303aaca00181ee53.zip
Introduce cowboy_http_req:body/1 to read the full request body.
Diffstat (limited to 'src/cowboy_http_req.erl')
-rw-r--r--src/cowboy_http_req.erl15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/cowboy_http_req.erl b/src/cowboy_http_req.erl
index a1688de..856c91c 100644
--- a/src/cowboy_http_req.erl
+++ b/src/cowboy_http_req.erl
@@ -25,7 +25,7 @@
]). %% Request API.
-export([
- body/2
+ body/1, body/2
]). %% Request Body API.
-export([
@@ -137,8 +137,19 @@ headers(Req) ->
%% Request Body API.
-%% @todo We probably want to configure the timeout.
%% @todo We probably want to allow a max length.
+-spec body(Req::#http_req{})
+ -> {Body::binary(), Req::#http_req{}} | {error, Reason::posix()}.
+body(Req) ->
+ {Length, Req2} = cowboy_http_req:header('Content-Length', Req),
+ case Length of
+ "" -> {error, badarg};
+ _Any ->
+ Length2 = list_to_integer(Length),
+ body(Length2, Req2)
+ end.
+
+%% @todo We probably want to configure the timeout.
-spec body(Length::non_neg_integer(), Req::#http_req{})
-> {Body::binary(), Req::#http_req{}} | {error, Reason::posix()}.
body(Length, Req=#http_req{socket=Socket, transport=Transport, body_state=waiting}) ->