diff options
author | Loïc Hoguin <[email protected]> | 2020-08-26 17:19:29 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2020-09-21 15:51:58 +0200 |
commit | 35d9f47fbcff23395c256b7814ce6af1d85129a2 (patch) | |
tree | 2bb4864409827488dd0c236d6983160e04937252 /src/gun_protocols.erl | |
parent | 3de0604eec218996dad4db59c0cc96092cd7e0e7 (diff) | |
download | gun-35d9f47fbcff23395c256b7814ce6af1d85129a2.tar.gz gun-35d9f47fbcff23395c256b7814ce6af1d85129a2.tar.bz2 gun-35d9f47fbcff23395c256b7814ce6af1d85129a2.zip |
Add a gun:stream_ref() type and fix Dialyzer
Diffstat (limited to 'src/gun_protocols.erl')
-rw-r--r-- | src/gun_protocols.erl | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/gun_protocols.erl b/src/gun_protocols.erl index e5c3c93..4209641 100644 --- a/src/gun_protocols.erl +++ b/src/gun_protocols.erl @@ -19,6 +19,8 @@ -export([handler_and_opts/2]). -export([negotiated/2]). +-spec add_stream_ref(Protocol, undefined | gun:stream_ref()) + -> Protocol when Protocol :: gun:protocol(). add_stream_ref(Protocol, undefined) -> Protocol; add_stream_ref({ProtocolName, ProtocolOpts}, StreamRef) -> @@ -26,6 +28,7 @@ add_stream_ref({ProtocolName, ProtocolOpts}, StreamRef) -> add_stream_ref(ProtocolName, StreamRef) -> {ProtocolName, #{stream_ref => StreamRef}}. +-spec handler(gun:protocol()) -> module(). handler(http) -> gun_http; handler({http, _}) -> gun_http; handler(http2) -> gun_http2; @@ -37,12 +40,15 @@ handler({socks, _}) -> gun_socks; handler(ws) -> gun_ws; handler({ws, _}) -> gun_ws. +-spec handler_and_opts(gun:protocol(), map()) -> {module(), map()}. handler_and_opts({ProtocolName, ProtocolOpts}, _) -> {handler(ProtocolName), ProtocolOpts}; handler_and_opts(ProtocolName, Opts) -> Protocol = handler(ProtocolName), {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; |