From 465d072abf4a76104d4562ed15345b27fe9a0cff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Wed, 21 Oct 2020 19:15:48 +0200 Subject: Fix cookie handling when tunnel and origin schemes mismatch The cookie_ignore_informational has been moved to http_opts and http2_opts. Also fix an issue when using 'protocols' in gun:open. When connecting via TLS the protocol's options were discarded. --- src/gun_protocols.erl | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src/gun_protocols.erl') diff --git a/src/gun_protocols.erl b/src/gun_protocols.erl index 65d5211..d297019 100644 --- a/src/gun_protocols.erl +++ b/src/gun_protocols.erl @@ -49,11 +49,23 @@ handler_and_opts(ProtocolName, Opts) -> {Protocol, maps:get(Protocol:opts_name(), Opts, #{})}. -spec negotiated({ok, binary()} | {error, protocol_not_negotiated}, gun:protocols()) - -> http | http2 | raw | socks. -negotiated({ok, <<"h2">>}, _) -> http2; -negotiated({ok, <<"http/1.1">>}, _) -> http; -negotiated({error, protocol_not_negotiated}, [Protocol]) -> Protocol; -negotiated({error, protocol_not_negotiated}, _) -> http. + -> gun:protocol(). +negotiated({ok, <<"h2">>}, Protocols) -> + lists:foldl(fun + (E = http2, _) -> E; + (E = {http2, _}, _) -> E; + (_, Acc) -> Acc + end, http2, Protocols); +negotiated({ok, <<"http/1.1">>}, Protocols) -> + lists:foldl(fun + (E = http, _) -> E; + (E = {http, _}, _) -> E; + (_, Acc) -> Acc + end, http, Protocols); +negotiated({error, protocol_not_negotiated}, [Protocol]) -> + Protocol; +negotiated({error, protocol_not_negotiated}, _) -> + http. -spec stream_ref(gun:protocol()) -> undefined | gun:stream_ref(). stream_ref({_, ProtocolOpts}) -> maps:get(stream_ref, ProtocolOpts, undefined); -- cgit v1.2.3