aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2011-09-06 03:24:53 -0700
committerLoïc Hoguin <[email protected]>2011-09-06 03:24:53 -0700
commit55ba8dc4daf3e3a49267ad6379802739498de534 (patch)
tree312938782b44ac073184252284d2de6a2bd57b3d /src
parent8bb7472fb0376e8020b93f30b4d460051310acc0 (diff)
parentbb469f6c3d2745251b333c89ef146624c934d5e2 (diff)
downloadcowboy-55ba8dc4daf3e3a49267ad6379802739498de534.tar.gz
cowboy-55ba8dc4daf3e3a49267ad6379802739498de534.tar.bz2
cowboy-55ba8dc4daf3e3a49267ad6379802739498de534.zip
Merge pull request #46 from tillitech/master
Fix the handling of HEAD requests
Diffstat (limited to 'src')
-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">>]).