aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/draft_h2_websockets_SUITE.erl10
-rw-r--r--test/rfc7540_SUITE.erl84
2 files changed, 92 insertions, 2 deletions
diff --git a/test/draft_h2_websockets_SUITE.erl b/test/draft_h2_websockets_SUITE.erl
index 31429df..bf7f537 100644
--- a/test/draft_h2_websockets_SUITE.erl
+++ b/test/draft_h2_websockets_SUITE.erl
@@ -78,7 +78,10 @@ reject_handshake_when_disabled(Config0) ->
}, Config0),
%% Connect to server and confirm that SETTINGS_ENABLE_CONNECT_PROTOCOL = 0.
{ok, Socket, Settings} = do_handshake(Config),
- #{enable_connect_protocol := false} = Settings,
+ case Settings of
+ #{enable_connect_protocol := false} -> ok;
+ _ when map_size(Settings) =:= 0 -> ok
+ end,
%% Send a CONNECT :protocol request to upgrade the stream to Websocket.
{ReqHeadersBlock, _} = cow_hpack:encode([
{<<":method">>, <<"CONNECT">>},
@@ -102,7 +105,10 @@ reject_handshake_disabled_by_default(Config0) ->
}, Config0),
%% Connect to server and confirm that SETTINGS_ENABLE_CONNECT_PROTOCOL = 0.
{ok, Socket, Settings} = do_handshake(Config),
- #{enable_connect_protocol := false} = Settings,
+ case Settings of
+ #{enable_connect_protocol := false} -> ok;
+ _ when map_size(Settings) =:= 0 -> ok
+ end,
%% Send a CONNECT :protocol request to upgrade the stream to Websocket.
{ReqHeadersBlock, _} = cow_hpack:encode([
{<<":method">>, <<"CONNECT">>},
diff --git a/test/rfc7540_SUITE.erl b/test/rfc7540_SUITE.erl
index 6c3d989..c125f17 100644
--- a/test/rfc7540_SUITE.erl
+++ b/test/rfc7540_SUITE.erl
@@ -18,6 +18,7 @@
-import(ct_helper, [config/2]).
-import(ct_helper, [doc/1]).
+-import(ct_helper, [name/0]).
-import(cowboy_test, [gun_open/1]).
-import(cowboy_test, [raw_open/1]).
-import(cowboy_test, [raw_send/2]).
@@ -2449,6 +2450,89 @@ continuation_with_extension_frame_interleaved_error(Config) ->
% (Section 5.4.1) of type PROTOCOL_ERROR.
%% (RFC7540 6.5.2)
+
+settings_header_table_size_client(Config) ->
+ doc("The SETTINGS_HEADER_TABLE_SIZE setting can be used to "
+ "inform the server of the maximum header table size "
+ "used by the client to decode header blocks. (RFC7540 6.5.2)"),
+ HeaderTableSize = 128,
+ %% Do the handhsake.
+ {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(#{header_table_size => HeaderTableSize})]),
+ %% Receive the server preface.
+ {ok, << Len0:24 >>} = gen_tcp:recv(Socket, 3, 1000),
+ {ok, << 4:8, 0:40, _:Len0/binary >>} = gen_tcp:recv(Socket, 6 + Len0, 1000),
+ %% Send the SETTINGS ack.
+ ok = gen_tcp:send(Socket, cow_http2:settings_ack()),
+ %% Receive the SETTINGS ack.
+ {ok, << 0:24, 4:8, 1:8, 0:32 >>} = gen_tcp:recv(Socket, 9, 1000),
+ %% Initialize decoding/encoding states.
+ DecodeState = cow_hpack:set_max_size(HeaderTableSize, cow_hpack:init()),
+ EncodeState = cow_hpack:init(),
+ %% Send a HEADERS frame as a request.
+ {ReqHeadersBlock1, _} = cow_hpack:encode([
+ {<<":method">>, <<"GET">>},
+ {<<":scheme">>, <<"http">>},
+ {<<":authority">>, <<"localhost">>}, %% @todo Correct port number.
+ {<<":path">>, <<"/">>}
+ ], EncodeState),
+ ok = gen_tcp:send(Socket, cow_http2:headers(1, fin, ReqHeadersBlock1)),
+ %% Receive a HEADERS frame as a response.
+ {ok, << Len1:24, 1:8, _:40 >>} = gen_tcp:recv(Socket, 9, 6000),
+ {ok, RespHeadersBlock1} = gen_tcp:recv(Socket, Len1, 6000),
+ {RespHeaders, _} = cow_hpack:decode(RespHeadersBlock1, DecodeState),
+ {_, <<"200">>} = lists:keyfind(<<":status">>, 1, RespHeaders),
+ %% The decoding succeeded, confirming that the table size is
+ %% lower than or equal to HeaderTableSize.
+ ok.
+
+settings_header_table_size_server(Config0) ->
+ doc("The SETTINGS_HEADER_TABLE_SIZE setting can be used to "
+ "inform the client of the maximum header table size "
+ "used by the server to decode header blocks. (RFC7540 6.5.2)"),
+ HeaderTableSize = 128,
+ %% Create a new listener that allows larger header table sizes.
+ Config = cowboy_test:init_http(name(), #{
+ env => #{dispatch => cowboy_router:compile(init_routes(Config0))},
+ max_decode_table_size => HeaderTableSize
+ }, Config0),
+ %% Do the handhsake.
+ {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(#{header_table_size => HeaderTableSize})]),
+ %% Receive the server preface.
+ {ok, << Len0:24 >>} = gen_tcp:recv(Socket, 3, 1000),
+ {ok, Data = <<_:48, _:Len0/binary>>} = gen_tcp:recv(Socket, 6 + Len0, 1000),
+ %% Confirm the server's SETTINGS_HEADERS_TABLE_SIZE uses HeaderTableSize.
+ {ok, {settings, #{header_table_size := HeaderTableSize}}, <<>>}
+ = cow_http2:parse(<<Len0:24, Data/binary>>),
+ %% Send the SETTINGS ack.
+ ok = gen_tcp:send(Socket, cow_http2:settings_ack()),
+ %% Receive the SETTINGS ack.
+ {ok, << 0:24, 4:8, 1:8, 0:32 >>} = gen_tcp:recv(Socket, 9, 1000),
+ %% Initialize decoding/encoding states.
+ DecodeState = cow_hpack:init(),
+ EncodeState = cow_hpack:set_max_size(HeaderTableSize, cow_hpack:init()),
+ %% Send a HEADERS frame as a request.
+ {ReqHeadersBlock1, _} = cow_hpack:encode([
+ {<<":method">>, <<"GET">>},
+ {<<":scheme">>, <<"http">>},
+ {<<":authority">>, <<"localhost">>}, %% @todo Correct port number.
+ {<<":path">>, <<"/">>}
+ ], EncodeState),
+ ok = gen_tcp:send(Socket, cow_http2:headers(1, fin, ReqHeadersBlock1)),
+ %% Receive a HEADERS frame as a response.
+ {ok, << Len1:24, 1:8, _:40 >>} = gen_tcp:recv(Socket, 9, 6000),
+ {ok, RespHeadersBlock1} = gen_tcp:recv(Socket, Len1, 6000),
+ {RespHeaders, _} = cow_hpack:decode(RespHeadersBlock1, DecodeState),
+ {_, <<"200">>} = lists:keyfind(<<":status">>, 1, RespHeaders),
+ %% The decoding succeeded on the server, confirming that
+ %% the table size was updated to HeaderTableSize.
+ ok.
+
% SETTINGS_ENABLE_PUSH (0x2): This setting can be used to disable
% server push (Section 8.2). An endpoint MUST NOT send a
% PUSH_PROMISE frame if it receives this parameter set to a value of