From 9a29aea148c55d12ac9141bc8c60b2456b4ef42b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Fri, 27 Apr 2018 17:58:11 +0200 Subject: Add options controlling maximum h2 frame sizes --- test/http2_SUITE.erl | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'test/http2_SUITE.erl') diff --git a/test/http2_SUITE.erl b/test/http2_SUITE.erl index 5b9ca95..3849303 100644 --- a/test/http2_SUITE.erl +++ b/test/http2_SUITE.erl @@ -28,15 +28,19 @@ groups() -> [{clear, [parallel], ct_helper:all(?MODULE)}]. init_routes(_) -> [ {"localhost", [ {"/", hello_h, []}, + {"/echo/:key", echo_h, []}, {"/resp_iolist_body", resp_iolist_body_h, []} ]} ]. -%% Do a prior knowledge handshake (function copied from rfc7540_SUITE). +%% Do a prior knowledge handshake (function originally copied from rfc7540_SUITE). do_handshake(Config) -> + do_handshake(#{}, Config). + +do_handshake(Settings, Config) -> {ok, Socket} = gen_tcp:connect("localhost", config(port, Config), [binary, {active, false}]), %% Send a valid preface. - ok = gen_tcp:send(Socket, ["PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n", cow_http2:settings(#{})]), + ok = gen_tcp:send(Socket, ["PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n", cow_http2:settings(Settings)]), %% Receive the server preface. {ok, << Len:24 >>} = gen_tcp:recv(Socket, 3, 1000), {ok, << 4:8, 0:40, _:Len/binary >>} = gen_tcp:recv(Socket, 6 + Len, 1000), @@ -81,6 +85,38 @@ initial_connection_window_size(Config) -> ConfiguredSize = Size + 65535, ok. +max_frame_size_sent(Config) -> + doc("Confirm that frames sent by Cowboy are limited in size " + "by the max_frame_size_sent configuration value."), + MaxFrameSize = 20000, + ProtoOpts = #{ + env => #{dispatch => cowboy_router:compile(init_routes(Config))}, + max_frame_size_sent => MaxFrameSize + }, + {ok, _} = cowboy:start_clear(name(), [{port, 0}], ProtoOpts), + Port = ranch:get_port(name()), + {ok, Socket} = do_handshake(#{max_frame_size => MaxFrameSize + 10000}, [{port, Port}|Config]), + %% Send a request with a 30000 bytes body. + {HeadersBlock, _} = cow_hpack:encode([ + {<<":method">>, <<"POST">>}, + {<<":scheme">>, <<"http">>}, + {<<":authority">>, <<"localhost">>}, %% @todo Correct port number. + {<<":path">>, <<"/echo/read_body">>} + ]), + ok = gen_tcp:send(Socket, [ + cow_http2:headers(1, nofin, HeadersBlock), + cow_http2:data(1, nofin, <<0:16384/unit:8>>), + cow_http2:data(1, fin, <<0:13616/unit:8>>) + ]), + %% Receive a HEADERS frame as a response. + {ok, <>} = gen_tcp:recv(Socket, 9, 6000), + {ok, _} = gen_tcp:recv(Socket, Len, 6000), + %% The DATA frames following must have lengths of 20000 + %% and then 10000 due to the limit. + {ok, <<20000:24, 0:8, _:40, _:20000/unit:8>>} = gen_tcp:recv(Socket, 20009, 6000), + {ok, <<10000:24, 0:8, _:40, _:10000/unit:8>>} = gen_tcp:recv(Socket, 10009, 6000), + ok. + preface_timeout_infinity(Config) -> doc("Ensure infinity for preface_timeout is accepted."), ProtoOpts = #{ -- cgit v1.2.3