aboutsummaryrefslogtreecommitdiffstats
path: root/src/gun_protocols.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/gun_protocols.erl')
-rw-r--r--src/gun_protocols.erl22
1 files changed, 17 insertions, 5 deletions
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);