Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix accessing HTTPS sites with an IPv4 address #494

Merged
merged 5 commits into from Jun 9, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/hackney_ssl.erl
Expand Up @@ -49,6 +49,13 @@ connect(Host, Port, Opts) ->

connect(Host, Port, Opts, Timeout) when is_list(Host), is_integer(Port),
(Timeout =:= infinity orelse is_integer(Timeout)) ->
Host1 = try
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be better to use inet:parse_address/1 there. Can you update your PR to use it? (sorry for the late answer)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, no problem. Just to be sure, you mean something like this, right?

f(Host) ->
    Host1 = case inet:parse_address(Host) of
             {ok, Address} -> Address;
             {error, _} -> Host
         end,
    Host1.

Would it be better if I moved this to a separate function, or should it remain inline in connect/4?

I will probably update the PR when I get home in the evening (can't really code right now, family&stuff...)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe in a separate function to make it more readable.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@piotrklibert would be cool if you can send your commit today to be part of the release. Let me know :)

Parts = string:split(Host, ".", all),
4 = length(Parts),
list_to_tuple(lists:map(fun list_to_integer/1, Parts))
catch
_:_ -> Host
end,
BaseOpts = [binary, {active, false}, {packet, raw},
{secure_renegotiate, true},
{reuse_sessions, true},
Expand All @@ -58,7 +65,7 @@ connect(Host, Port, Opts, Timeout) when is_list(Host), is_integer(Port),
Opts1 = hackney_util:merge_opts(BaseOpts, Opts),

%% connect
ssl:connect(Host, Port, Opts1, Timeout).
ssl:connect(Host1, Port, Opts1, Timeout).


ciphers() ->
Expand Down