Просмотр исходного кода

Make cowboy_req:has_body/1 return boolean()

This makes it similar to the other has_* functions.
Loïc Hoguin 12 лет назад
Родитель
Сommit
82de4254dd

+ 3 - 3
examples/echo_post/src/toppage_handler.erl

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

+ 3 - 4
src/cowboy_req.erl

@@ -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.
 %%

+ 2 - 2
test/http_handler_echo_body.erl

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