Browse Source

Add HTTP/2 tests with responses with HTTP/1.1 specific headers

Loïc Hoguin 5 years ago
parent
commit
57badc9082
2 changed files with 60 additions and 2 deletions
  1. 10 0
      test/handlers/resp_h.erl
  2. 50 2
      test/rfc7540_SUITE.erl

+ 10 - 0
test/handlers/resp_h.erl

@@ -39,6 +39,16 @@ do(<<"set_resp_headers">>, Req0, Opts) ->
 		<<"content-encoding">> => <<"compress">>
 		<<"content-encoding">> => <<"compress">>
 	}, Req0),
 	}, Req0),
 	{ok, cowboy_req:reply(200, #{}, "OK", Req), Opts};
 	{ok, cowboy_req:reply(200, #{}, "OK", Req), Opts};
+do(<<"set_resp_headers_http11">>, Req0, Opts) ->
+	Req = cowboy_req:set_resp_headers(#{
+		<<"connection">> => <<"custom-header, close">>,
+		<<"custom-header">> => <<"value">>,
+		<<"keep-alive">> => <<"timeout=5, max=1000">>,
+		<<"proxy-connection">> => <<"close">>,
+		<<"transfer-encoding">> => <<"chunked">>,
+		<<"upgrade">> => <<"HTTP/1.1">>
+	}, Req0),
+	{ok, cowboy_req:reply(200, #{}, "OK", Req), Opts};
 do(<<"resp_header_defined">>, Req0, Opts) ->
 do(<<"resp_header_defined">>, Req0, Opts) ->
 	Req1 = cowboy_req:set_resp_header(<<"content-type">>, <<"text/plain">>, Req0),
 	Req1 = cowboy_req:set_resp_header(<<"content-type">>, <<"text/plain">>, Req0),
 	<<"text/plain">> = cowboy_req:resp_header(<<"content-type">>, Req1),
 	<<"text/plain">> = cowboy_req:resp_header(<<"content-type">>, Req1),

+ 50 - 2
test/rfc7540_SUITE.erl

@@ -33,11 +33,11 @@ groups() ->
 	[{clear, [parallel], Clear}, {tls, [parallel], TLS}].
 	[{clear, [parallel], Clear}, {tls, [parallel], TLS}].
 
 
 init_per_group(Name = clear, Config) ->
 init_per_group(Name = clear, Config) ->
-	cowboy_test:init_http(Name, #{
+	[{protocol, http2}|cowboy_test:init_http(Name, #{
 		env => #{dispatch => cowboy_router:compile(init_routes(Config))},
 		env => #{dispatch => cowboy_router:compile(init_routes(Config))},
 		%% Disable the DATA threshold for this test suite.
 		%% Disable the DATA threshold for this test suite.
 		stream_window_data_threshold => 0
 		stream_window_data_threshold => 0
-	}, Config);
+	}, Config)];
 init_per_group(Name = tls, Config) ->
 init_per_group(Name = tls, Config) ->
 	cowboy_test:init_http2(Name, #{
 	cowboy_test:init_http2(Name, #{
 		env => #{dispatch => cowboy_router:compile(init_routes(Config))},
 		env => #{dispatch => cowboy_router:compile(init_routes(Config))},
@@ -3643,6 +3643,54 @@ reject_te_header_other_values(Config) ->
 %   Transfer-Encoding, and Upgrade, even if they are not nominated by the
 %   Transfer-Encoding, and Upgrade, even if they are not nominated by the
 %   Connection header field.
 %   Connection header field.
 
 
+response_dont_send_header_in_connection(Config) ->
+	doc("Intermediaries must remove HTTP/1.1 connection headers when "
+		"transforming an HTTP/1.1 messages to HTTP/2. The server must "
+		"not send them either. All headers listed in the connection "
+		"header must be removed. (RFC7540 8.1.2.2)"),
+	do_response_dont_send_http11_header(Config, <<"custom-header">>).
+
+response_dont_send_connection_header(Config) ->
+	doc("Intermediaries must remove HTTP/1.1 connection headers when "
+		"transforming an HTTP/1.1 messages to HTTP/2. The server must "
+		"not send them either. The connection header must be removed. (RFC7540 8.1.2.2)"),
+	do_response_dont_send_http11_header(Config, <<"connection">>).
+
+response_dont_send_keep_alive_header(Config) ->
+	doc("Intermediaries must remove HTTP/1.1 connection headers when "
+		"transforming an HTTP/1.1 messages to HTTP/2. The server must "
+		"not send them either. The keep-alive header must be removed "
+		"even if not listed in the connection header. (RFC7540 8.1.2.2)"),
+	do_response_dont_send_http11_header(Config, <<"keep-alive">>).
+
+response_dont_send_proxy_connection_header(Config) ->
+	doc("Intermediaries must remove HTTP/1.1 connection headers when "
+		"transforming an HTTP/1.1 messages to HTTP/2. The server must "
+		"not send them either. The proxy-connection header must be removed "
+		"even if not listed in the connection header. (RFC7540 8.1.2.2)"),
+	do_response_dont_send_http11_header(Config, <<"proxy-connection">>).
+
+response_dont_send_transfer_encoding_header(Config) ->
+	doc("Intermediaries must remove HTTP/1.1 connection headers when "
+		"transforming an HTTP/1.1 messages to HTTP/2. The server must "
+		"not send them either. The transfer-encoding header must be removed "
+		"even if not listed in the connection header. (RFC7540 8.1.2.2)"),
+	do_response_dont_send_http11_header(Config, <<"transfer-encoding">>).
+
+response_dont_send_upgrade_header(Config) ->
+	doc("Intermediaries must remove HTTP/1.1 connection headers when "
+		"transforming an HTTP/1.1 messages to HTTP/2. The server must "
+		"not send them either. The upgrade header must be removed "
+		"even if not listed in the connection header. (RFC7540 8.1.2.2)"),
+	do_response_dont_send_http11_header(Config, <<"upgrade">>).
+
+do_response_dont_send_http11_header(Config, Name) ->
+	ConnPid = gun_open(Config),
+	Ref = gun:get(ConnPid, "/resp/set_resp_headers_http11"),
+	{response, nofin, 200, Headers} = gun:await(ConnPid, Ref),
+	false = lists:keyfind(Name, 1, Headers),
+	ok.
+
 reject_userinfo(Config) ->
 reject_userinfo(Config) ->
 	doc("An authority containing a userinfo component must be rejected "
 	doc("An authority containing a userinfo component must be rejected "
 		"with a PROTOCOL_ERROR stream error. (RFC7540 8.1.2.3, RFC7540 8.1.2.6)"),
 		"with a PROTOCOL_ERROR stream error. (RFC7540 8.1.2.3, RFC7540 8.1.2.6)"),