From 839f31e97504e10b8eef4897aa1271a53137cc29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Wed, 26 Aug 2020 17:34:56 +0200 Subject: Add more HTTP/2 CONNECT tests --- src/gun_http2.erl | 1 + test/rfc7540_SUITE.erl | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) 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. -- cgit v1.2.3