Skip to content

Commit

Permalink
Rewrite of SNI fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbevemyr committed Mar 14, 2021
1 parent 901ef12 commit c3ecb9b
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/gun.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1098,20 +1098,19 @@ ensure_alpn_sni(Protocols0, TransOpts0, OriginHost) ->
{alpn_advertised_protocols, Protocols},
{client_preferred_next_protocols, {client, Protocols, <<"http/1.1">>}}
|TransOpts0],
%% Only add SNI if not already present
%% SNI.
%%
%% Normally only DNS hostnames are supported for SNI. However, the ssl
%% application itself allows any string through so we do the same.
%%
%% Only add SNI if not already present and OriginHost isn't an IP
case lists:keymember(server_name_indication, 1, TransOpts) of
true ->
TransOpts;
false ->
%% SNI.
%%
%% Normally only DNS hostnames are supported for SNI. However, the ssl
%% application itself allows any string through so we do the same.
if
is_list(OriginHost) -> [{server_name_indication, OriginHost}|TransOpts];
is_atom(OriginHost) -> [{server_name_indication, atom_to_list(OriginHost)}|TransOpts];
true -> TransOpts
end
false when is_list(OriginHost) ->
[{server_name_indication, OriginHost}|TransOpts];
false when is_atom(OriginHost) ->
[{server_name_indication, atom_to_list(OriginHost)}|TransOpts];
_ ->
TransOpts
end.

%% Normal TLS handshake.
Expand Down

0 comments on commit c3ecb9b

Please sign in to comment.