aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAli Sabil <[email protected]>2011-09-06 12:11:44 +0200
committerAli Sabil <[email protected]>2011-09-06 12:11:44 +0200
commitbb469f6c3d2745251b333c89ef146624c934d5e2 (patch)
tree312938782b44ac073184252284d2de6a2bd57b3d
parent8bb7472fb0376e8020b93f30b4d460051310acc0 (diff)
downloadcowboy-bb469f6c3d2745251b333c89ef146624c934d5e2.tar.gz
cowboy-bb469f6c3d2745251b333c89ef146624c934d5e2.tar.bz2
cowboy-bb469f6c3d2745251b333c89ef146624c934d5e2.zip
Fix the handling of the HEAD requests
Responses to the HEAD requests used to include an response body.
-rw-r--r--src/cowboy_http_req.erl17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/cowboy_http_req.erl b/src/cowboy_http_req.erl
index 69d47b0..5b63599 100644
--- a/src/cowboy_http_req.erl
+++ b/src/cowboy_http_req.erl
@@ -264,7 +264,7 @@ body_qs(Req) ->
-> {ok, #http_req{}}.
reply(Code, Headers, Body, Req=#http_req{socket=Socket,
transport=Transport, connection=Connection,
- resp_state=waiting}) ->
+ method=Method, resp_state=waiting}) ->
Head = response_head(Code, Headers, [
{<<"Connection">>, atom_to_connection(Connection)},
{<<"Content-Length">>,
@@ -272,7 +272,10 @@ reply(Code, Headers, Body, Req=#http_req{socket=Socket,
{<<"Date">>, cowboy_clock:rfc1123()},
{<<"Server">>, <<"Cowboy">>}
]),
- Transport:send(Socket, [Head, Body]),
+ case Method of
+ 'HEAD' -> Transport:send(Socket, Head);
+ _ -> Transport:send(Socket, [Head, Body])
+ end,
{ok, Req#http_req{resp_state=done}}.
%% @doc Initiate the sending of a chunked reply to the client.
@@ -280,6 +283,14 @@ reply(Code, Headers, Body, Req=#http_req{socket=Socket,
-spec chunked_reply(http_status(), http_headers(), #http_req{})
-> {ok, #http_req{}}.
chunked_reply(Code, Headers, Req=#http_req{socket=Socket, transport=Transport,
+ method='HEAD', resp_state=waiting}) ->
+ Head = response_head(Code, Headers, [
+ {<<"Date">>, cowboy_clock:rfc1123()},
+ {<<"Server">>, <<"Cowboy">>}
+ ]),
+ Transport:send(Socket, Head),
+ {ok, Req#http_req{resp_state=done}};
+chunked_reply(Code, Headers, Req=#http_req{socket=Socket, transport=Transport,
resp_state=waiting}) ->
Head = response_head(Code, Headers, [
{<<"Connection">>, <<"close">>},
@@ -294,6 +305,8 @@ chunked_reply(Code, Headers, Req=#http_req{socket=Socket, transport=Transport,
%%
%% A chunked reply must have been initiated before calling this function.
-spec chunk(iodata(), #http_req{}) -> ok.
+chunk(_Data, #http_req{socket=_Socket, transport=_Transport, method='HEAD'}) ->
+ ok;
chunk(Data, #http_req{socket=Socket, transport=Transport, resp_state=chunks}) ->
Transport:send(Socket, [integer_to_list(iolist_size(Data), 16),
<<"\r\n">>, Data, <<"\r\n">>]).