aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2014-03-23 21:14:28 +0100
committerLoïc Hoguin <[email protected]>2014-03-23 21:14:28 +0100
commit26ef371ec4e0c8f2b6132c7e46d1b8b8b1992b7d (patch)
tree4f6867b1e7fb2c77dce7652c8769d2d30d4df70b
parentd2481b936863c29dbad95ffac29e6740f92acb45 (diff)
downloadgun-26ef371ec4e0c8f2b6132c7e46d1b8b8b1992b7d.tar.gz
gun-26ef371ec4e0c8f2b6132c7e46d1b8b8b1992b7d.tar.bz2
gun-26ef371ec4e0c8f2b6132c7e46d1b8b8b1992b7d.zip
NPN isn't supported on R15
We branch out and don't try to use NPN when the function ssl:negotiated_next_protocol/1 isn't exported.
-rw-r--r--src/gun.erl19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/gun.erl b/src/gun.erl
index e666ae5..8834f4d 100644
--- a/src/gun.erl
+++ b/src/gun.erl
@@ -345,13 +345,22 @@ init(Parent, Owner, Host, Port, Opts) ->
connect(State=#state{owner=Owner, host=Host, port=Port, type=ssl,
proto_opts=HTTPOpts}, Retries) ->
Transport = ranch_ssl,
- Opts = [binary, {active, false}, {client_preferred_next_protocols,
- {client, [<<"spdy/3">>, <<"http/1.1">>], <<"http/1.1">>}}],
+ %% R15 support.
+ HasNPN = erlang:function_exported(ssl, negotiated_next_protocol, 1),
+ Opts = [binary, {active, false}
+ |[{client_preferred_next_protocols,
+ {client, [<<"spdy/3">>, <<"http/1.1">>], <<"http/1.1">>}}
+ || HasNPN]],
case Transport:connect(Host, Port, Opts) of
{ok, Socket} ->
- {Protocol, ProtoOpts} = case ssl:negotiated_next_protocol(Socket) of
- {ok, <<"spdy/3">>} -> {gun_spdy, []};
- _ -> {gun_http, HTTPOpts}
+ {Protocol, ProtoOpts} = case HasNPN of
+ false ->
+ {gun_http, HTTPOpts};
+ true ->
+ case ssl:negotiated_next_protocol(Socket) of
+ {ok, <<"spdy/3">>} -> {gun_spdy, []};
+ _ -> {gun_http, HTTPOpts}
+ end
end,
ProtoState = Protocol:init(Owner, Socket, Transport, ProtoOpts),
before_loop(State#state{socket=Socket, transport=Transport,