mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 12:20:24 +00:00
Make cowboy_req:has_body/1 return boolean()
This makes it similar to the other has_* functions.
This commit is contained in:
parent
645556a80a
commit
82de4254dd
3 changed files with 8 additions and 9 deletions
|
@ -12,9 +12,9 @@ init(_Transport, Req, []) ->
|
|||
|
||||
handle(Req, State) ->
|
||||
{Method, Req2} = cowboy_req:method(Req),
|
||||
{HasBody, Req3} = cowboy_req:has_body(Req2),
|
||||
{ok, Req4} = maybe_echo(Method, HasBody, Req3),
|
||||
{ok, Req4, State}.
|
||||
HasBody = cowboy_req:has_body(Req2),
|
||||
{ok, Req3} = maybe_echo(Method, HasBody, Req2),
|
||||
{ok, Req3, State}.
|
||||
|
||||
maybe_echo(<<"POST">>, true, Req) ->
|
||||
{ok, PostVals, Req2} = cowboy_req:body_qs(Req),
|
||||
|
|
|
@ -555,11 +555,10 @@ set_meta(Name, Value, Req=#http_req{meta=Meta}) ->
|
|||
%% Request Body API.
|
||||
|
||||
%% @doc Return whether the request message has a body.
|
||||
-spec has_body(Req) -> {boolean(), Req} when Req::req().
|
||||
-spec has_body(cowboy_req:req()) -> boolean().
|
||||
has_body(Req) ->
|
||||
Has = lists:keymember(<<"content-length">>, 1, Req#http_req.headers) orelse
|
||||
lists:keymember(<<"transfer-encoding">>, 1, Req#http_req.headers),
|
||||
{Has, Req}.
|
||||
lists:keymember(<<"content-length">>, 1, Req#http_req.headers) orelse
|
||||
lists:keymember(<<"transfer-encoding">>, 1, Req#http_req.headers).
|
||||
|
||||
%% @doc Return the request message body length, if known.
|
||||
%%
|
||||
|
|
|
@ -8,8 +8,8 @@ init({_, http}, Req, _) ->
|
|||
{ok, Req, undefined}.
|
||||
|
||||
handle(Req, State) ->
|
||||
{true, Req1} = cowboy_req:has_body(Req),
|
||||
{ok, Body, Req2} = cowboy_req:body(Req1),
|
||||
true = cowboy_req:has_body(Req),
|
||||
{ok, Body, Req2} = cowboy_req:body(Req),
|
||||
{Size, Req3} = cowboy_req:body_length(Req2),
|
||||
Size = byte_size(Body),
|
||||
{ok, Req4} = cowboy_req:reply(200, [], Body, Req3),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue