0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 20:30:23 +00:00

Fix reading the request body when Length < byte_size(Buffer)

This commit is contained in:
Loïc Hoguin 2011-11-07 19:17:49 +01:00
parent 6dbe2b2130
commit 12b9ca3526

View file

@ -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) ->