Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion THANKS
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ Richard Jones <[email protected]>
Eduardo Gurgel <[email protected]>
Mayorov Andrey <[email protected]>
omarkj <[email protected]>
Pavel Abalihin <[email protected]>
Pavel Abalikhin <[email protected]>
Ilya Khaprov <[email protected]>
5 changes: 5 additions & 0 deletions src/hackney.erl
Original file line number Diff line number Diff line change
Expand Up @@ -801,9 +801,14 @@ redirect(Client0, {Method, NewLocation, Headers, Body}) ->
Client1 = hackney_connect:check_or_close(Client),

%% update the state with the redirect info
RedirectNetloc = hackney_url:netloc(
hackney_url:transport_scheme(RedirectTransport),
RedirectHost,
RedirectPort),
Client2 = Client1#client{transport=RedirectTransport,
host=RedirectHost,
port=RedirectPort,
netloc=RedirectNetloc,
options=Opts},

%% send a request to the new location
Expand Down
8 changes: 2 additions & 6 deletions src/hackney_connect.erl
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,8 @@ create_connection(Transport, Host, Port, Options) ->

create_connection(Transport, Host, Port, Options, Dynamic)
when is_list(Options) ->
Netloc = case {Transport, Port} of
{hackney_tcp, 80} -> list_to_binary(Host);
{hackney_ssl, 443} -> list_to_binary(Host);
_ ->
iolist_to_binary([Host, ":", integer_to_list(Port)])
end,
Netloc = hackney_url:netloc(hackney_url:transport_scheme(Transport),
Host, Port),
%% default timeout
Timeout = proplists:get_value(recv_timeout, Options, ?RECV_TIMEOUT),
FollowRedirect = proplists:get_value(follow_redirect, Options, false),
Expand Down
19 changes: 11 additions & 8 deletions src/hackney_url.erl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

-export([parse_url/1,
transport_scheme/1,
netloc/3,
unparse_url/1,
urldecode/1, urldecode/2,
urlencode/1, urlencode/2,
Expand Down Expand Up @@ -94,14 +95,7 @@ normalize(#hackney_url{}=Url, Fun) when is_function(Fun, 1) ->

%% encode domain if needed
Host2 = idna:to_ascii(Host1),
Netloc1 = case {Scheme, Port} of
{http, 80} -> list_to_binary(Host2);
{https, 443} -> list_to_binary(Host2);
{http_unix, _} -> list_to_binary(Host2);
_ ->
iolist_to_binary([Host2, ":", integer_to_list(Port)])
end,
{Host2, Netloc1}
{Host2, netloc(Scheme, Host2, Port)}
end,
Path1 = Fun(Path),
Url#hackney_url{host=Host, netloc=Netloc, path=Path1}.
Expand All @@ -113,6 +107,15 @@ transport_scheme(hackney_ssl) ->
transport_scheme(hackney_local_tcp) ->
http_unix.

netloc(http, Host, 80) ->
list_to_binary(Host);
netloc(https, Host, 443) ->
list_to_binary(Host);
netloc(http_unix, Host, _Port) ->
list_to_binary(Host);
netloc(_, Host, Port) ->
iolist_to_binary([Host, ":", integer_to_list(Port)]).

unparse_url(#hackney_url{}=Url) ->
#hackney_url{scheme = Scheme,
netloc = Netloc,
Expand Down