aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2020-08-26 17:34:56 +0200
committerLoïc Hoguin <[email protected]>2020-09-21 15:51:58 +0200
commit839f31e97504e10b8eef4897aa1271a53137cc29 (patch)
tree3d478b8914d412b0156d5fc630b8435ed174266a
parent35d9f47fbcff23395c256b7814ce6af1d85129a2 (diff)
downloadgun-839f31e97504e10b8eef4897aa1271a53137cc29.tar.gz
gun-839f31e97504e10b8eef4897aa1271a53137cc29.tar.bz2
gun-839f31e97504e10b8eef4897aa1271a53137cc29.zip
Add more HTTP/2 CONNECT tests
-rw-r--r--src/gun_http2.erl1
-rw-r--r--test/rfc7540_SUITE.erl21
2 files changed, 22 insertions, 0 deletions
diff --git a/src/gun_http2.erl b/src/gun_http2.erl
index 6863b84..3687946 100644
--- a/src/gun_http2.erl
+++ b/src/gun_http2.erl
@@ -875,6 +875,7 @@ request(State0=#http2_state{socket=Socket, transport=Transport, opts=Opts,
request(State, [StreamRef|Tail], ReplyTo, Method, _Host, _Port,
Path, Headers, Body, InitialFlow, EvHandler, EvHandlerState0) ->
case get_stream_by_ref(State, StreamRef) of
+ %% @todo We should send an error to the user if the stream isn't ready.
Stream=#stream{tunnel={Proto, ProtoState0, TunnelInfo=#{
origin_host := OriginHost, origin_port := OriginPort}}} ->
%% @todo So the event is probably not giving the right StreamRef?
diff --git a/test/rfc7540_SUITE.erl b/test/rfc7540_SUITE.erl
index 2ceecdd..8669b13 100644
--- a/test/rfc7540_SUITE.erl
+++ b/test/rfc7540_SUITE.erl
@@ -561,21 +561,41 @@ connect_cowboy_http_via_h2c(_) ->
"to an HTTP/1.1 server via a TCP HTTP/2 proxy. (RFC7540 8.3)"),
do_connect_cowboy(<<"http">>, tcp, http, <<"http">>, tcp).
+connect_cowboy_https_via_h2c(_) ->
+ doc("CONNECT can be used to establish a TLS connection "
+ "to an HTTP/1.1 server via a TCP HTTP/2 proxy. (RFC7540 8.3)"),
+ do_connect_cowboy(<<"https">>, tls, http, <<"http">>, tcp).
+
connect_cowboy_http_via_h2(_) ->
doc("CONNECT can be used to establish a TCP connection "
"to an HTTP/1.1 server via a TLS HTTP/2 proxy. (RFC7540 8.3)"),
do_connect_cowboy(<<"http">>, tcp, http, <<"https">>, tls).
+connect_cowboy_https_via_h2(_) ->
+ doc("CONNECT can be used to establish a TLS connection "
+ "to an HTTP/1.1 server via a TLS HTTP/2 proxy. (RFC7540 8.3)"),
+ do_connect_cowboy(<<"https">>, tls, http, <<"https">>, tls).
+
connect_cowboy_h2c_via_h2c(_) ->
doc("CONNECT can be used to establish a TCP connection "
"to an HTTP/2 server via a TCP HTTP/2 proxy. (RFC7540 8.3)"),
do_connect_cowboy(<<"http">>, tcp, http2, <<"http">>, tcp).
+connect_cowboy_h2_via_h2c(_) ->
+ doc("CONNECT can be used to establish a TLS connection "
+ "to an HTTP/2 server via a TCP HTTP/2 proxy. (RFC7540 8.3)"),
+ do_connect_cowboy(<<"https">>, tls, http2, <<"http">>, tcp).
+
connect_cowboy_h2c_via_h2(_) ->
doc("CONNECT can be used to establish a TCP connection "
"to an HTTP/2 server via a TLS HTTP/2 proxy. (RFC7540 8.3)"),
do_connect_cowboy(<<"http">>, tcp, http2, <<"https">>, tls).
+connect_cowboy_h2_via_h2(_) ->
+ doc("CONNECT can be used to establish a TLS connection "
+ "to an HTTP/2 server via a TLS HTTP/2 proxy. (RFC7540 8.3)"),
+ do_connect_cowboy(<<"https">>, tls, http2, <<"https">>, tls).
+
do_connect_cowboy(_OriginScheme, OriginTransport, OriginProtocol, _ProxyScheme, ProxyTransport) ->
{ok, Ref, OriginPort} = do_cowboy_origin(OriginTransport, OriginProtocol),
try
@@ -601,6 +621,7 @@ do_connect_cowboy(_OriginScheme, OriginTransport, OriginProtocol, _ProxyScheme,
<<":authority">> := Authority
}} = receive_from(ProxyPid),
{response, nofin, 200, _} = gun:await(ConnPid, StreamRef),
+ {up, OriginProtocol} = gun:await(ConnPid, StreamRef),
ProxiedStreamRef = gun:get(ConnPid, "/proxied", #{}, #{tunnel => StreamRef}),
{response, nofin, 200, _} = gun:await(ConnPid, ProxiedStreamRef),
%% We can create more requests on the proxy as well.