aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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">>]).