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:
parent
6dbe2b2130
commit
12b9ca3526
1 changed files with 3 additions and 2 deletions
|
@ -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) ->
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue