aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2011-11-07 19:17:49 +0100
committerLoïc Hoguin <[email protected]>2011-11-07 19:17:49 +0100
commit12b9ca352616afcf865670df9e2186df213bd9f1 (patch)
treecbb960dc46cdb8949e8b5a01d54b128c908d4eee /src
parent6dbe2b21300c2324766edaf1619272d65f5faaed (diff)
downloadcowboy-12b9ca352616afcf865670df9e2186df213bd9f1.tar.gz
cowboy-12b9ca352616afcf865670df9e2186df213bd9f1.tar.bz2
cowboy-12b9ca352616afcf865670df9e2186df213bd9f1.zip
Fix reading the request body when Length < byte_size(Buffer)
Diffstat (limited to 'src')
-rw-r--r--src/cowboy_http_req.erl5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/cowboy_http_req.erl b/src/cowboy_http_req.erl
index 5a63e98..feb795c 100644
--- a/src/cowboy_http_req.erl
+++ b/src/cowboy_http_req.erl
@@ -326,8 +326,9 @@ body(Req) ->
-spec body(non_neg_integer(), #http_req{})
-> {ok, binary(), #http_req{}} | {error, atom()}.
body(Length, Req=#http_req{body_state=waiting, buffer=Buffer})
- when Length =:= byte_size(Buffer) ->
- {ok, Buffer, Req#http_req{body_state=done, buffer= <<>>}};
+ when Length =< byte_size(Buffer) ->
+ << Body:Length/binary, Rest/bits >> = Buffer,
+ {ok, Body, Req#http_req{body_state=done, buffer=Rest}};
body(Length, Req=#http_req{socket=Socket, transport=Transport,
body_state=waiting, buffer=Buffer})
when is_integer(Length) andalso Length > byte_size(Buffer) ->