From 2690d1254caffa2d85965baf95ed005c39fc820a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Wed, 26 Dec 2012 18:51:41 +0100 Subject: 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. --- src/cowboy_req.erl | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) (limited to 'src') 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} -> -- cgit v1.2.3