Permalink
Browse files

Merge pull request #15 from josevalim/no-stream-on-head

Don't stream the response body on head requests
  • Loading branch information...
2 parents 5aff165 + c618a74 commit 035d3de6a16a4738f246988d23dffec1417d13b6 @benoitc committed Nov 13, 2012
Showing with 5 additions and 3 deletions.
  1. +1 −0 include/hackney.hrl
  2. +2 −1 src/hackney_request.erl
  3. +2 −2 src/hackney_response.erl
View
@@ -60,6 +60,7 @@
clen = nil,
te = nil,
connection = nil,
+ method = nil,
ctype = nil}).
-record(hackney_url, {
@@ -88,7 +88,8 @@ perform(Client0, {Method0, Path, Headers0, Body0}) ->
E;
{ok, Client2} ->
case end_stream_body(Client2) of
- {ok, FinalClient} ->
+ {ok, Client3} ->
+ FinalClient = Client3#client{method=Method},
hackney_response:start_response(FinalClient);
Error ->
Error
@@ -134,12 +134,12 @@ parse_header(Line, Client) ->
{header, {Key, Value}, Client1}.
-stream_body(Client=#client{body_state=waiting, te=TE, clen=Length}) ->
+stream_body(Client=#client{body_state=waiting, te=TE, clen=Length, method=Method}) ->
case TE of
<<"chunked">> ->
stream_body(Client#client{body_state=
{stream, fun te_chunked/2, {0, 0}, fun ce_identity/1}});
- _ when Length =:= 0 ->
+ _ when Length =:= 0 orelse Method =:= <<"HEAD">> ->
{done, Client#client{body_state=done}};
_ ->
stream_body(Client#client{body_state=

0 comments on commit 035d3de

Please sign in to comment.