diff options
author | Loïc Hoguin <[email protected]> | 2014-03-23 21:14:28 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2014-03-23 21:14:28 +0100 |
commit | 26ef371ec4e0c8f2b6132c7e46d1b8b8b1992b7d (patch) | |
tree | 4f6867b1e7fb2c77dce7652c8769d2d30d4df70b /src | |
parent | d2481b936863c29dbad95ffac29e6740f92acb45 (diff) | |
download | gun-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.
Diffstat (limited to 'src')
-rw-r--r-- | src/gun.erl | 19 |
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, |