From 26ef371ec4e0c8f2b6132c7e46d1b8b8b1992b7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Sun, 23 Mar 2014 21:14:28 +0100 Subject: 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. --- src/gun.erl | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src') 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, -- cgit v1.2.3