aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2012-12-26 18:51:41 +0100
committerLoïc Hoguin <[email protected]>2012-12-26 18:51:41 +0100
commit2690d1254caffa2d85965baf95ed005c39fc820a (patch)
tree23b81836cdb87b48b0ca697267fc4d8bc4b26db0 /src
parentf401a84be6788867fcf4544dc2c88b5751b55039 (diff)
downloadcowboy-2690d1254caffa2d85965baf95ed005c39fc820a.tar.gz
cowboy-2690d1254caffa2d85965baf95ed005c39fc820a.tar.bz2
cowboy-2690d1254caffa2d85965baf95ed005c39fc820a.zip
Remove cowboy_req:body/2
This function was badly thought out and would cause more harm than good if used at all. Recommendation will be for people who need to limit body length to check it beforehand or when not possible to use the stream_body API.
Diffstat (limited to 'src')
-rw-r--r--src/cowboy_req.erl20
1 files changed, 4 insertions, 16 deletions
diff --git a/src/cowboy_req.erl b/src/cowboy_req.erl
index da9d2c0..4a9e1a7 100644
--- a/src/cowboy_req.erl
+++ b/src/cowboy_req.erl
@@ -81,7 +81,6 @@
-export([stream_body/1]).
-export([skip_body/1]).
-export([body/1]).
--export([body/2]).
-export([body_qs/1]).
-export([multipart_data/1]).
-export([multipart_skip/1]).
@@ -698,25 +697,14 @@ content_decode(ContentDecode, Data, Req) ->
%% @doc Return the full body sent with the request.
-spec body(Req) -> {ok, binary(), Req} | {error, atom()} when Req::req().
body(Req) ->
- read_body(infinity, Req, <<>>).
+ body(Req, <<>>).
-%% @doc Return the full body sent with the request as long as the body
-%% length doesn't go over MaxLength.
-%%
-%% This is most useful to quickly be able to get the full body while
-%% avoiding filling your memory with huge request bodies when you're
-%% not expecting it.
--spec body(non_neg_integer() | infinity, Req)
- -> {ok, binary(), Req} | {error, atom()} when Req::req().
-body(MaxLength, Req) ->
- read_body(MaxLength, Req, <<>>).
-
--spec read_body(non_neg_integer() | infinity, Req, binary())
+-spec body(Req, binary())
-> {ok, binary(), Req} | {error, atom()} when Req::req().
-read_body(MaxLength, Req, Acc) when MaxLength > byte_size(Acc) ->
+body(Req, Acc) ->
case stream_body(Req) of
{ok, Data, Req2} ->
- read_body(MaxLength, Req2, << Acc/binary, Data/binary >>);
+ body(Req2, << Acc/binary, Data/binary >>);
{done, Req2} ->
{ok, Acc, Req2};
{error, Reason} ->