Skip to content

Commit

Permalink
Url encode host header for unix domain sockets
Browse files Browse the repository at this point in the history
When sending the `host` header for a request to a unix domain socket
the value must be url encoded, since most such values have invalid
slash characters. (fixes benoitc#382)
  • Loading branch information
fishliver committed Jan 28, 2017
1 parent 02115f8 commit 45bde8c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/hackney.erl
Original file line number Diff line number Diff line change
Expand Up @@ -561,12 +561,19 @@ stop_async(Ref) ->
%%
%%
%%
host_header(#hackney_url{netloc=Netloc}, Headers) ->
host_header(#hackney_url{transport=Transport,netloc=Netloc}, Headers) ->
case proplists:get_value(<<"Host">>, Headers) of
undefined -> Headers ++ [{<<"Host">>, Netloc}];
undefined ->
Host = host_header_encode(Transport, Netloc),
Headers ++ [{<<"Host">>, Host}];
_ -> Headers
end.

host_header_encode(hackney_local_tcp, Netloc) ->
hackney_url:urlencode(Netloc);
host_header_encode(_Transport, Netloc) -> Netloc.


make_request(connect, #hackney_url{}=URL, Headers, Body, _, _) ->
#hackney_url{host = Host,
port = Port}= URL,
Expand Down

0 comments on commit 45bde8c

Please sign in to comment.