mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-15 04:30:25 +00:00
Simplify the guards for cowboy_http_req:body/2
This commit is contained in:
parent
0201f7f2b2
commit
3649b0ee0d
1 changed files with 2 additions and 3 deletions
|
@ -341,12 +341,11 @@ body(Req) ->
|
||||||
-spec body(non_neg_integer(), #http_req{})
|
-spec body(non_neg_integer(), #http_req{})
|
||||||
-> {ok, binary(), #http_req{}} | {error, atom()}.
|
-> {ok, binary(), #http_req{}} | {error, atom()}.
|
||||||
body(Length, Req=#http_req{body_state=waiting, buffer=Buffer})
|
body(Length, Req=#http_req{body_state=waiting, buffer=Buffer})
|
||||||
when Length =< byte_size(Buffer) ->
|
when is_integer(Length) andalso Length =< byte_size(Buffer) ->
|
||||||
<< Body:Length/binary, Rest/bits >> = Buffer,
|
<< Body:Length/binary, Rest/bits >> = Buffer,
|
||||||
{ok, Body, Req#http_req{body_state=done, buffer=Rest}};
|
{ok, Body, Req#http_req{body_state=done, buffer=Rest}};
|
||||||
body(Length, Req=#http_req{socket=Socket, transport=Transport,
|
body(Length, Req=#http_req{socket=Socket, transport=Transport,
|
||||||
body_state=waiting, buffer=Buffer})
|
body_state=waiting, buffer=Buffer}) ->
|
||||||
when is_integer(Length) andalso Length > byte_size(Buffer) ->
|
|
||||||
case Transport:recv(Socket, Length - byte_size(Buffer), 5000) of
|
case Transport:recv(Socket, Length - byte_size(Buffer), 5000) of
|
||||||
{ok, Body} -> {ok, << Buffer/binary, Body/binary >>,
|
{ok, Body} -> {ok, << Buffer/binary, Body/binary >>,
|
||||||
Req#http_req{body_state=done, buffer= <<>>}};
|
Req#http_req{body_state=done, buffer= <<>>}};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue