aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2020-11-12 15:27:07 +0100
committerLoïc Hoguin <[email protected]>2020-11-12 15:27:07 +0100
commit492c955819eec864e3f3ea2760d3ee7800851356 (patch)
tree67046c8bd94cc875b9d0887d721cc3e55ba0950c /src
parent093dcd5fdefb6df0d316624665c584f37040cdd8 (diff)
downloadgun-492c955819eec864e3f3ea2760d3ee7800851356.tar.gz
gun-492c955819eec864e3f3ea2760d3ee7800851356.tar.bz2
gun-492c955819eec864e3f3ea2760d3ee7800851356.zip
Return 'undefined' for raw|socks origin_scheme where applicable
Diffstat (limited to 'src')
-rw-r--r--src/gun.erl9
-rw-r--r--src/gun_http2.erl10
-rw-r--r--src/gun_socks.erl3
-rw-r--r--src/gun_tunnel.erl16
4 files changed, 24 insertions, 14 deletions
diff --git a/src/gun.erl b/src/gun.erl
index ddb5007..6251dc7 100644
--- a/src/gun.erl
+++ b/src/gun.erl
@@ -466,6 +466,7 @@ info(ServerPid) ->
end,
origin_scheme => case Protocol of
gun_raw -> undefined;
+ gun_socks -> undefined;
_ -> OriginScheme
end,
origin_host => OriginHost,
@@ -943,7 +944,8 @@ start_link(Owner, Host, Port, Opts) ->
init({Owner, Host, Port, Opts}) ->
Retry = maps:get(retry, Opts, 5),
OriginTransport = maps:get(transport, Opts, default_transport(Port)),
- %% @todo The OriginScheme is not http when we connect to socks/raw.
+ %% The OriginScheme is not really http when we connect to socks/raw.
+ %% This is corrected in the gun:info/1 and gun:stream_info/2 functions where applicable.
{OriginScheme, Transport} = case OriginTransport of
tcp -> {<<"http">>, gun_tcp};
tls -> {<<"https">>, gun_tls}
@@ -1542,7 +1544,10 @@ tunnel_info_from_state(#state{origin_scheme=OriginScheme,
<<"https">> -> tls
end,
protocol => Proto:name(),
- origin_scheme => OriginScheme,
+ origin_scheme => case Proto of
+ gun_raw -> undefined;
+ _ -> OriginScheme
+ end,
origin_host => OriginHost,
origin_port => OriginPort
}.
diff --git a/src/gun_http2.erl b/src/gun_http2.erl
index 9c8e094..2778b4f 100644
--- a/src/gun_http2.erl
+++ b/src/gun_http2.erl
@@ -1256,16 +1256,18 @@ stream_info(State, StreamRef) when is_reference(StreamRef) ->
info=#{origin_host := OriginHost, origin_port := OriginPort},
protocol=Proto, protocol_state=ProtoState}} ->
Transport = maps:get(transport, Destination, tcp),
+ Protocol = Proto:tunneled_name(ProtoState, true),
{ok, #{
ref => StreamRef,
reply_to => ReplyTo,
state => running,
tunnel => #{
transport => Transport,
- protocol => Proto:tunneled_name(ProtoState, true),
- origin_scheme => case Transport of
- tcp -> <<"http">>;
- tls -> <<"https">>
+ protocol => Protocol,
+ origin_scheme => case {Transport, Protocol} of
+ {_, raw} -> undefined;
+ {tcp, _} -> <<"http">>;
+ {tls, _} -> <<"https">>
end,
origin_host => OriginHost,
origin_port => OriginPort
diff --git a/src/gun_socks.erl b/src/gun_socks.erl
index cda4f98..541949f 100644
--- a/src/gun_socks.erl
+++ b/src/gun_socks.erl
@@ -137,7 +137,8 @@ handle(<<5, 0, 0, Rest0/bits>>, #socks_state{ref=StreamRef, reply_to=ReplyTo, op
end,
%% @todo Maybe an event indicating success.
#{host := NewHost, port := NewPort} = Opts,
- %% @todo The origin scheme is wrong when the next protocol is not HTTP.
+ %% There is no origin scheme when not using HTTP but we act as if
+ %% there is and simply correct the value in the info functions.
case Opts of
#{transport := tls} ->
HandshakeEvent0 = #{
diff --git a/src/gun_tunnel.erl b/src/gun_tunnel.erl
index 72f97f7..43e8767 100644
--- a/src/gun_tunnel.erl
+++ b/src/gun_tunnel.erl
@@ -362,19 +362,21 @@ stream_info(#tunnel_state{transport=Transport0, stream_ref=TunnelStreamRef, repl
gun_tcp_proxy -> tcp;
gun_tls_proxy -> tls
end,
+ Protocol = case Proto of
+ gun_tunnel -> Proto:tunneled_name(ProtoState, false);
+ _ -> Proto:name()
+ end,
{ok, #{
ref => TunnelStreamRef,
reply_to => ReplyTo,
state => running,
tunnel => #{
transport => Transport,
- protocol => case Proto of
- gun_tunnel -> Proto:tunneled_name(ProtoState, false);
- _ -> Proto:name()
- end,
- origin_scheme => case Transport of
- tcp -> <<"http">>;
- tls -> <<"https">>
+ protocol => Protocol,
+ origin_scheme => case {Transport, Protocol} of
+ {_, raw} -> undefined;
+ {tcp, _} -> <<"http">>;
+ {tls, _} -> <<"https">>
end,
origin_host => OriginHost,
origin_port => OriginPort