mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 20:30:23 +00:00
Use try..after in tests that start their own listeners
This commit is contained in:
parent
bed328b6c9
commit
d2f367fba3
5 changed files with 631 additions and 524 deletions
|
@ -58,11 +58,14 @@ idle_timeout(Config) ->
|
||||||
},
|
},
|
||||||
{ok, _} = cowboy:start_clear(?FUNCTION_NAME, [{port, 0}], ProtoOpts),
|
{ok, _} = cowboy:start_clear(?FUNCTION_NAME, [{port, 0}], ProtoOpts),
|
||||||
Port = ranch:get_port(?FUNCTION_NAME),
|
Port = ranch:get_port(?FUNCTION_NAME),
|
||||||
|
try
|
||||||
{ok, Socket} = do_handshake([{port, Port}|Config]),
|
{ok, Socket} = do_handshake([{port, Port}|Config]),
|
||||||
timer:sleep(1000),
|
timer:sleep(1000),
|
||||||
%% Receive a GOAWAY frame back with NO_ERROR.
|
%% Receive a GOAWAY frame back with NO_ERROR.
|
||||||
{ok, << _:24, 7:8, _:72, 0:32 >>} = gen_tcp:recv(Socket, 17, 1000),
|
{ok, << _:24, 7:8, _:72, 0:32 >>} = gen_tcp:recv(Socket, 17, 1000)
|
||||||
ok.
|
after
|
||||||
|
cowboy:stop_listener(?FUNCTION_NAME)
|
||||||
|
end.
|
||||||
|
|
||||||
idle_timeout_infinity(Config) ->
|
idle_timeout_infinity(Config) ->
|
||||||
doc("Ensure the idle_timeout option accepts the infinity value."),
|
doc("Ensure the idle_timeout option accepts the infinity value."),
|
||||||
|
@ -72,11 +75,14 @@ idle_timeout_infinity(Config) ->
|
||||||
},
|
},
|
||||||
{ok, _} = cowboy:start_clear(?FUNCTION_NAME, [{port, 0}], ProtoOpts),
|
{ok, _} = cowboy:start_clear(?FUNCTION_NAME, [{port, 0}], ProtoOpts),
|
||||||
Port = ranch:get_port(?FUNCTION_NAME),
|
Port = ranch:get_port(?FUNCTION_NAME),
|
||||||
|
try
|
||||||
{ok, Socket} = do_handshake([{port, Port}|Config]),
|
{ok, Socket} = do_handshake([{port, Port}|Config]),
|
||||||
timer:sleep(1000),
|
timer:sleep(1000),
|
||||||
%% Don't receive a GOAWAY frame.
|
%% Don't receive a GOAWAY frame.
|
||||||
{error, timeout} = gen_tcp:recv(Socket, 17, 1000),
|
{error, timeout} = gen_tcp:recv(Socket, 17, 1000)
|
||||||
ok.
|
after
|
||||||
|
cowboy:stop_listener(?FUNCTION_NAME)
|
||||||
|
end.
|
||||||
|
|
||||||
idle_timeout_reset_on_data(Config) ->
|
idle_timeout_reset_on_data(Config) ->
|
||||||
doc("Terminate when the idle timeout is reached."),
|
doc("Terminate when the idle timeout is reached."),
|
||||||
|
@ -86,6 +92,7 @@ idle_timeout_reset_on_data(Config) ->
|
||||||
},
|
},
|
||||||
{ok, _} = cowboy:start_clear(?FUNCTION_NAME, [{port, 0}], ProtoOpts),
|
{ok, _} = cowboy:start_clear(?FUNCTION_NAME, [{port, 0}], ProtoOpts),
|
||||||
Port = ranch:get_port(?FUNCTION_NAME),
|
Port = ranch:get_port(?FUNCTION_NAME),
|
||||||
|
try
|
||||||
{ok, Socket} = do_handshake([{port, Port}|Config]),
|
{ok, Socket} = do_handshake([{port, Port}|Config]),
|
||||||
%% We wait a little, send a PING, receive a PING ack.
|
%% We wait a little, send a PING, receive a PING ack.
|
||||||
{error, timeout} = gen_tcp:recv(Socket, 17, 500),
|
{error, timeout} = gen_tcp:recv(Socket, 17, 500),
|
||||||
|
@ -101,8 +108,10 @@ idle_timeout_reset_on_data(Config) ->
|
||||||
{ok, <<8:24, 6:8, 0:7, 1:1, 0:96>>} = gen_tcp:recv(Socket, 17, 1000),
|
{ok, <<8:24, 6:8, 0:7, 1:1, 0:96>>} = gen_tcp:recv(Socket, 17, 1000),
|
||||||
%% The connection goes away soon after we stop sending data.
|
%% The connection goes away soon after we stop sending data.
|
||||||
timer:sleep(1000),
|
timer:sleep(1000),
|
||||||
{ok, << _:24, 7:8, _:72, 0:32 >>} = gen_tcp:recv(Socket, 17, 1000),
|
{ok, << _:24, 7:8, _:72, 0:32 >>} = gen_tcp:recv(Socket, 17, 1000)
|
||||||
ok.
|
after
|
||||||
|
cowboy:stop_listener(?FUNCTION_NAME)
|
||||||
|
end.
|
||||||
|
|
||||||
inactivity_timeout(Config) ->
|
inactivity_timeout(Config) ->
|
||||||
doc("Terminate when the inactivity timeout is reached."),
|
doc("Terminate when the inactivity timeout is reached."),
|
||||||
|
@ -112,11 +121,14 @@ inactivity_timeout(Config) ->
|
||||||
},
|
},
|
||||||
{ok, _} = cowboy:start_clear(?FUNCTION_NAME, [{port, 0}], ProtoOpts),
|
{ok, _} = cowboy:start_clear(?FUNCTION_NAME, [{port, 0}], ProtoOpts),
|
||||||
Port = ranch:get_port(?FUNCTION_NAME),
|
Port = ranch:get_port(?FUNCTION_NAME),
|
||||||
|
try
|
||||||
{ok, Socket} = do_handshake([{port, Port}|Config]),
|
{ok, Socket} = do_handshake([{port, Port}|Config]),
|
||||||
receive after 1000 -> ok end,
|
receive after 1000 -> ok end,
|
||||||
%% Receive a GOAWAY frame back with an INTERNAL_ERROR.
|
%% Receive a GOAWAY frame back with an INTERNAL_ERROR.
|
||||||
{ok, << _:24, 7:8, _:72, 2:32 >>} = gen_tcp:recv(Socket, 17, 1000),
|
{ok, << _:24, 7:8, _:72, 2:32 >>} = gen_tcp:recv(Socket, 17, 1000)
|
||||||
ok.
|
after
|
||||||
|
cowboy:stop_listener(?FUNCTION_NAME)
|
||||||
|
end.
|
||||||
|
|
||||||
initial_connection_window_size(Config) ->
|
initial_connection_window_size(Config) ->
|
||||||
doc("Confirm a WINDOW_UPDATE frame is sent when the configured "
|
doc("Confirm a WINDOW_UPDATE frame is sent when the configured "
|
||||||
|
@ -128,6 +140,7 @@ initial_connection_window_size(Config) ->
|
||||||
},
|
},
|
||||||
{ok, _} = cowboy:start_clear(?FUNCTION_NAME, [{port, 0}], ProtoOpts),
|
{ok, _} = cowboy:start_clear(?FUNCTION_NAME, [{port, 0}], ProtoOpts),
|
||||||
Port = ranch:get_port(?FUNCTION_NAME),
|
Port = ranch:get_port(?FUNCTION_NAME),
|
||||||
|
try
|
||||||
{ok, Socket} = gen_tcp:connect("localhost", Port, [binary, {active, false}]),
|
{ok, Socket} = gen_tcp:connect("localhost", Port, [binary, {active, false}]),
|
||||||
%% Send a valid preface.
|
%% 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(#{})]),
|
||||||
|
@ -136,8 +149,10 @@ initial_connection_window_size(Config) ->
|
||||||
{ok, << 4:8, 0:40, _:Len/binary >>} = gen_tcp:recv(Socket, 6 + Len, 1000),
|
{ok, << 4:8, 0:40, _:Len/binary >>} = gen_tcp:recv(Socket, 6 + Len, 1000),
|
||||||
%% Receive a WINDOW_UPDATE frame incrementing the connection window to 100000.
|
%% Receive a WINDOW_UPDATE frame incrementing the connection window to 100000.
|
||||||
{ok, <<4:24, 8:8, 0:41, Size:31>>} = gen_tcp:recv(Socket, 13, 1000),
|
{ok, <<4:24, 8:8, 0:41, Size:31>>} = gen_tcp:recv(Socket, 13, 1000),
|
||||||
ConfiguredSize = Size + 65535,
|
ConfiguredSize = Size + 65535
|
||||||
ok.
|
after
|
||||||
|
cowboy:stop_listener(?FUNCTION_NAME)
|
||||||
|
end.
|
||||||
|
|
||||||
max_frame_size_sent(Config) ->
|
max_frame_size_sent(Config) ->
|
||||||
doc("Confirm that frames sent by Cowboy are limited in size "
|
doc("Confirm that frames sent by Cowboy are limited in size "
|
||||||
|
@ -149,7 +164,9 @@ max_frame_size_sent(Config) ->
|
||||||
},
|
},
|
||||||
{ok, _} = cowboy:start_clear(?FUNCTION_NAME, [{port, 0}], ProtoOpts),
|
{ok, _} = cowboy:start_clear(?FUNCTION_NAME, [{port, 0}], ProtoOpts),
|
||||||
Port = ranch:get_port(?FUNCTION_NAME),
|
Port = ranch:get_port(?FUNCTION_NAME),
|
||||||
{ok, Socket} = do_handshake(#{max_frame_size => MaxFrameSize + 10000}, [{port, Port}|Config]),
|
try
|
||||||
|
{ok, Socket} = do_handshake(#{max_frame_size => MaxFrameSize + 10000},
|
||||||
|
[{port, Port}|Config]),
|
||||||
%% Send a request with a 30000 bytes body.
|
%% Send a request with a 30000 bytes body.
|
||||||
{HeadersBlock, _} = cow_hpack:encode([
|
{HeadersBlock, _} = cow_hpack:encode([
|
||||||
{<<":method">>, <<"POST">>},
|
{<<":method">>, <<"POST">>},
|
||||||
|
@ -175,9 +192,10 @@ max_frame_size_sent(Config) ->
|
||||||
%% The DATA frames following must have lengths of 20000
|
%% The DATA frames following must have lengths of 20000
|
||||||
%% and then 10000 due to the limit.
|
%% and then 10000 due to the limit.
|
||||||
{ok, <<20000:24, 0:8, _:40, _:20000/unit:8>>} = gen_tcp:recv(Socket, 20009, 6000),
|
{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, <<10000:24, 0:8, _:40, _:10000/unit:8>>} = gen_tcp:recv(Socket, 10009, 6000)
|
||||||
%% Stop the listener.
|
after
|
||||||
cowboy:stop_listener(?FUNCTION_NAME).
|
cowboy:stop_listener(?FUNCTION_NAME)
|
||||||
|
end.
|
||||||
|
|
||||||
preface_timeout_infinity(Config) ->
|
preface_timeout_infinity(Config) ->
|
||||||
doc("Ensure infinity for preface_timeout is accepted."),
|
doc("Ensure infinity for preface_timeout is accepted."),
|
||||||
|
@ -187,6 +205,7 @@ preface_timeout_infinity(Config) ->
|
||||||
},
|
},
|
||||||
{ok, _} = cowboy:start_clear(?FUNCTION_NAME, [{port, 0}], ProtoOpts),
|
{ok, _} = cowboy:start_clear(?FUNCTION_NAME, [{port, 0}], ProtoOpts),
|
||||||
Port = ranch:get_port(?FUNCTION_NAME),
|
Port = ranch:get_port(?FUNCTION_NAME),
|
||||||
|
try
|
||||||
{ok, Socket} = do_handshake([{port, Port}|Config]),
|
{ok, Socket} = do_handshake([{port, Port}|Config]),
|
||||||
Pid = get_remote_pid_tcp(Socket),
|
Pid = get_remote_pid_tcp(Socket),
|
||||||
Ref = erlang:monitor(process, Pid),
|
Ref = erlang:monitor(process, Pid),
|
||||||
|
@ -194,6 +213,9 @@ preface_timeout_infinity(Config) ->
|
||||||
{'DOWN', Ref, process, Pid, Reason} ->
|
{'DOWN', Ref, process, Pid, Reason} ->
|
||||||
error(Reason)
|
error(Reason)
|
||||||
after 1000 ->
|
after 1000 ->
|
||||||
|
ok
|
||||||
|
end
|
||||||
|
after
|
||||||
cowboy:stop_listener(?FUNCTION_NAME)
|
cowboy:stop_listener(?FUNCTION_NAME)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -206,6 +228,7 @@ resp_iolist_body(Config) ->
|
||||||
},
|
},
|
||||||
{ok, _} = cowboy:start_clear(?FUNCTION_NAME, [{port, 0}], ProtoOpts),
|
{ok, _} = cowboy:start_clear(?FUNCTION_NAME, [{port, 0}], ProtoOpts),
|
||||||
Port = ranch:get_port(?FUNCTION_NAME),
|
Port = ranch:get_port(?FUNCTION_NAME),
|
||||||
|
try
|
||||||
ConnPid = gun_open([{type, tcp}, {protocol, http2}, {port, Port}|Config]),
|
ConnPid = gun_open([{type, tcp}, {protocol, http2}, {port, Port}|Config]),
|
||||||
Ref = gun:get(ConnPid, "/resp_iolist_body"),
|
Ref = gun:get(ConnPid, "/resp_iolist_body"),
|
||||||
{response, nofin, 200, RespHeaders} = gun:await(ConnPid, Ref),
|
{response, nofin, 200, RespHeaders} = gun:await(ConnPid, Ref),
|
||||||
|
@ -213,7 +236,10 @@ resp_iolist_body(Config) ->
|
||||||
Len = binary_to_integer(BinLen),
|
Len = binary_to_integer(BinLen),
|
||||||
{ok, RespBody} = gun:await_body(ConnPid, Ref),
|
{ok, RespBody} = gun:await_body(ConnPid, Ref),
|
||||||
Len = iolist_size(RespBody),
|
Len = iolist_size(RespBody),
|
||||||
gun:close(ConnPid).
|
gun:close(ConnPid)
|
||||||
|
after
|
||||||
|
cowboy:stop_listener(?FUNCTION_NAME)
|
||||||
|
end.
|
||||||
|
|
||||||
settings_timeout_infinity(Config) ->
|
settings_timeout_infinity(Config) ->
|
||||||
doc("Ensure infinity for settings_timeout is accepted."),
|
doc("Ensure infinity for settings_timeout is accepted."),
|
||||||
|
@ -223,6 +249,7 @@ settings_timeout_infinity(Config) ->
|
||||||
},
|
},
|
||||||
{ok, _} = cowboy:start_clear(?FUNCTION_NAME, [{port, 0}], ProtoOpts),
|
{ok, _} = cowboy:start_clear(?FUNCTION_NAME, [{port, 0}], ProtoOpts),
|
||||||
Port = ranch:get_port(?FUNCTION_NAME),
|
Port = ranch:get_port(?FUNCTION_NAME),
|
||||||
|
try
|
||||||
{ok, Socket} = do_handshake([{port, Port}|Config]),
|
{ok, Socket} = do_handshake([{port, Port}|Config]),
|
||||||
Pid = get_remote_pid_tcp(Socket),
|
Pid = get_remote_pid_tcp(Socket),
|
||||||
Ref = erlang:monitor(process, Pid),
|
Ref = erlang:monitor(process, Pid),
|
||||||
|
@ -230,5 +257,8 @@ settings_timeout_infinity(Config) ->
|
||||||
{'DOWN', Ref, process, Pid, Reason} ->
|
{'DOWN', Ref, process, Pid, Reason} ->
|
||||||
error(Reason)
|
error(Reason)
|
||||||
after 1000 ->
|
after 1000 ->
|
||||||
|
ok
|
||||||
|
end
|
||||||
|
after
|
||||||
cowboy:stop_listener(?FUNCTION_NAME)
|
cowboy:stop_listener(?FUNCTION_NAME)
|
||||||
end.
|
end.
|
||||||
|
|
|
@ -47,6 +47,7 @@ chunked_false(Config) ->
|
||||||
chunked => false
|
chunked => false
|
||||||
}),
|
}),
|
||||||
Port = ranch:get_port(?FUNCTION_NAME),
|
Port = ranch:get_port(?FUNCTION_NAME),
|
||||||
|
try
|
||||||
Request = "GET /resp/stream_reply2/200 HTTP/1.1\r\nhost: localhost\r\n\r\n",
|
Request = "GET /resp/stream_reply2/200 HTTP/1.1\r\nhost: localhost\r\n\r\n",
|
||||||
Client = raw_open([{type, tcp}, {port, Port}, {opts, []}|Config]),
|
Client = raw_open([{type, tcp}, {port, Port}, {opts, []}|Config]),
|
||||||
ok = raw_send(Client, Request),
|
ok = raw_send(Client, Request),
|
||||||
|
@ -62,8 +63,10 @@ chunked_false(Config) ->
|
||||||
end,
|
end,
|
||||||
Bits = 8000000 - bit_size(Rest),
|
Bits = 8000000 - bit_size(Rest),
|
||||||
raw_expect_recv(Client, <<0:Bits>>),
|
raw_expect_recv(Client, <<0:Bits>>),
|
||||||
{error, closed} = raw_recv(Client, 1, 1000),
|
{error, closed} = raw_recv(Client, 1, 1000)
|
||||||
ok.
|
after
|
||||||
|
cowboy:stop_listener(?FUNCTION_NAME)
|
||||||
|
end.
|
||||||
|
|
||||||
http10_keepalive_false(Config) ->
|
http10_keepalive_false(Config) ->
|
||||||
doc("Confirm the option http10_keepalive => false disables keep-alive "
|
doc("Confirm the option http10_keepalive => false disables keep-alive "
|
||||||
|
@ -73,6 +76,7 @@ http10_keepalive_false(Config) ->
|
||||||
http10_keepalive => false
|
http10_keepalive => false
|
||||||
}),
|
}),
|
||||||
Port = ranch:get_port(?FUNCTION_NAME),
|
Port = ranch:get_port(?FUNCTION_NAME),
|
||||||
|
try
|
||||||
Keepalive = "GET / HTTP/1.0\r\nhost: localhost\r\nConnection: keep-alive\r\n\r\n",
|
Keepalive = "GET / HTTP/1.0\r\nhost: localhost\r\nConnection: keep-alive\r\n\r\n",
|
||||||
Client = raw_open([{type, tcp}, {port, Port}, {opts, []}|Config]),
|
Client = raw_open([{type, tcp}, {port, Port}, {opts, []}|Config]),
|
||||||
ok = raw_send(Client, Keepalive),
|
ok = raw_send(Client, Keepalive),
|
||||||
|
@ -88,6 +92,9 @@ http10_keepalive_false(Config) ->
|
||||||
case catch raw_recv_head(Client) of
|
case catch raw_recv_head(Client) of
|
||||||
{'EXIT', _} -> closed;
|
{'EXIT', _} -> closed;
|
||||||
_ -> error(not_closed)
|
_ -> error(not_closed)
|
||||||
|
end
|
||||||
|
after
|
||||||
|
cowboy:stop_listener(?FUNCTION_NAME)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
idle_timeout_infinity(Config) ->
|
idle_timeout_infinity(Config) ->
|
||||||
|
@ -98,6 +105,7 @@ idle_timeout_infinity(Config) ->
|
||||||
idle_timeout => infinity
|
idle_timeout => infinity
|
||||||
}),
|
}),
|
||||||
Port = ranch:get_port(?FUNCTION_NAME),
|
Port = ranch:get_port(?FUNCTION_NAME),
|
||||||
|
try
|
||||||
ConnPid = gun_open([{type, tcp}, {protocol, http}, {port, Port}|Config]),
|
ConnPid = gun_open([{type, tcp}, {protocol, http}, {port, Port}|Config]),
|
||||||
_ = gun:post(ConnPid, "/echo/read_body",
|
_ = gun:post(ConnPid, "/echo/read_body",
|
||||||
[{<<"content-type">>, <<"text/plain">>}]),
|
[{<<"content-type">>, <<"text/plain">>}]),
|
||||||
|
@ -109,6 +117,9 @@ idle_timeout_infinity(Config) ->
|
||||||
error(Reason)
|
error(Reason)
|
||||||
after 1000 ->
|
after 1000 ->
|
||||||
ok
|
ok
|
||||||
|
end
|
||||||
|
after
|
||||||
|
cowboy:stop_listener(?FUNCTION_NAME)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
request_timeout_infinity(Config) ->
|
request_timeout_infinity(Config) ->
|
||||||
|
@ -118,6 +129,7 @@ request_timeout_infinity(Config) ->
|
||||||
idle_timeout => infinity
|
idle_timeout => infinity
|
||||||
}),
|
}),
|
||||||
Port = ranch:get_port(?FUNCTION_NAME),
|
Port = ranch:get_port(?FUNCTION_NAME),
|
||||||
|
try
|
||||||
ConnPid = gun_open([{type, tcp}, {protocol, http}, {port, Port}|Config]),
|
ConnPid = gun_open([{type, tcp}, {protocol, http}, {port, Port}|Config]),
|
||||||
#{socket := Socket} = gun:info(ConnPid),
|
#{socket := Socket} = gun:info(ConnPid),
|
||||||
Pid = get_remote_pid_tcp(Socket),
|
Pid = get_remote_pid_tcp(Socket),
|
||||||
|
@ -127,6 +139,9 @@ request_timeout_infinity(Config) ->
|
||||||
error(Reason)
|
error(Reason)
|
||||||
after 1000 ->
|
after 1000 ->
|
||||||
ok
|
ok
|
||||||
|
end
|
||||||
|
after
|
||||||
|
cowboy:stop_listener(?FUNCTION_NAME)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
set_options_chunked_false(Config) ->
|
set_options_chunked_false(Config) ->
|
||||||
|
@ -138,6 +153,7 @@ set_options_chunked_false(Config) ->
|
||||||
chunked => true
|
chunked => true
|
||||||
}),
|
}),
|
||||||
Port = ranch:get_port(?FUNCTION_NAME),
|
Port = ranch:get_port(?FUNCTION_NAME),
|
||||||
|
try
|
||||||
Request = "GET /set_options/chunked_false HTTP/1.1\r\nhost: localhost\r\n\r\n",
|
Request = "GET /set_options/chunked_false HTTP/1.1\r\nhost: localhost\r\n\r\n",
|
||||||
Client = raw_open([{type, tcp}, {port, Port}, {opts, []}|Config]),
|
Client = raw_open([{type, tcp}, {port, Port}, {opts, []}|Config]),
|
||||||
ok = raw_send(Client, Request),
|
ok = raw_send(Client, Request),
|
||||||
|
@ -151,8 +167,10 @@ set_options_chunked_false(Config) ->
|
||||||
false = lists:keyfind(<<"transfer-encoding">>, 1, Headers)
|
false = lists:keyfind(<<"transfer-encoding">>, 1, Headers)
|
||||||
end,
|
end,
|
||||||
raw_expect_recv(Client, <<0:8000000>>),
|
raw_expect_recv(Client, <<0:8000000>>),
|
||||||
{error, closed} = raw_recv(Client, 1, 1000),
|
{error, closed} = raw_recv(Client, 1, 1000)
|
||||||
ok.
|
after
|
||||||
|
cowboy:stop_listener(?FUNCTION_NAME)
|
||||||
|
end.
|
||||||
|
|
||||||
set_options_chunked_false_ignored(Config) ->
|
set_options_chunked_false_ignored(Config) ->
|
||||||
doc("Confirm the option chunked can be dynamically set to disable "
|
doc("Confirm the option chunked can be dynamically set to disable "
|
||||||
|
@ -163,6 +181,7 @@ set_options_chunked_false_ignored(Config) ->
|
||||||
chunked => true
|
chunked => true
|
||||||
}),
|
}),
|
||||||
Port = ranch:get_port(?FUNCTION_NAME),
|
Port = ranch:get_port(?FUNCTION_NAME),
|
||||||
|
try
|
||||||
ConnPid = gun_open([{type, tcp}, {protocol, http}, {port, Port}|Config]),
|
ConnPid = gun_open([{type, tcp}, {protocol, http}, {port, Port}|Config]),
|
||||||
%% We do a first request setting the option but not
|
%% We do a first request setting the option but not
|
||||||
%% using chunked transfer-encoding in the response.
|
%% using chunked transfer-encoding in the response.
|
||||||
|
@ -173,8 +192,10 @@ set_options_chunked_false_ignored(Config) ->
|
||||||
%% is not disabled for that second request.
|
%% is not disabled for that second request.
|
||||||
StreamRef2 = gun:get(ConnPid, "/resp/stream_reply2/200"),
|
StreamRef2 = gun:get(ConnPid, "/resp/stream_reply2/200"),
|
||||||
{response, nofin, 200, Headers} = gun:await(ConnPid, StreamRef2),
|
{response, nofin, 200, Headers} = gun:await(ConnPid, StreamRef2),
|
||||||
{_, <<"chunked">>} = lists:keyfind(<<"transfer-encoding">>, 1, Headers),
|
{_, <<"chunked">>} = lists:keyfind(<<"transfer-encoding">>, 1, Headers)
|
||||||
ok.
|
after
|
||||||
|
cowboy:stop_listener(?FUNCTION_NAME)
|
||||||
|
end.
|
||||||
|
|
||||||
set_options_idle_timeout(Config) ->
|
set_options_idle_timeout(Config) ->
|
||||||
doc("Confirm that the idle_timeout option can be dynamically "
|
doc("Confirm that the idle_timeout option can be dynamically "
|
||||||
|
@ -185,6 +206,7 @@ set_options_idle_timeout(Config) ->
|
||||||
idle_timeout => 60000
|
idle_timeout => 60000
|
||||||
}),
|
}),
|
||||||
Port = ranch:get_port(?FUNCTION_NAME),
|
Port = ranch:get_port(?FUNCTION_NAME),
|
||||||
|
try
|
||||||
ConnPid = gun_open([{type, tcp}, {protocol, http}, {port, Port}|Config]),
|
ConnPid = gun_open([{type, tcp}, {protocol, http}, {port, Port}|Config]),
|
||||||
_ = gun:post(ConnPid, "/set_options/idle_timeout_short",
|
_ = gun:post(ConnPid, "/set_options/idle_timeout_short",
|
||||||
[{<<"content-type">>, <<"text/plain">>}]),
|
[{<<"content-type">>, <<"text/plain">>}]),
|
||||||
|
@ -196,6 +218,9 @@ set_options_idle_timeout(Config) ->
|
||||||
ok
|
ok
|
||||||
after 2000 ->
|
after 2000 ->
|
||||||
error(timeout)
|
error(timeout)
|
||||||
|
end
|
||||||
|
after
|
||||||
|
cowboy:stop_listener(?FUNCTION_NAME)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
set_options_idle_timeout_only_applies_to_current_request(Config) ->
|
set_options_idle_timeout_only_applies_to_current_request(Config) ->
|
||||||
|
@ -206,6 +231,7 @@ set_options_idle_timeout_only_applies_to_current_request(Config) ->
|
||||||
idle_timeout => 500
|
idle_timeout => 500
|
||||||
}),
|
}),
|
||||||
Port = ranch:get_port(?FUNCTION_NAME),
|
Port = ranch:get_port(?FUNCTION_NAME),
|
||||||
|
try
|
||||||
ConnPid = gun_open([{type, tcp}, {protocol, http}, {port, Port}|Config]),
|
ConnPid = gun_open([{type, tcp}, {protocol, http}, {port, Port}|Config]),
|
||||||
StreamRef = gun:post(ConnPid, "/set_options/idle_timeout_long",
|
StreamRef = gun:post(ConnPid, "/set_options/idle_timeout_long",
|
||||||
[{<<"content-type">>, <<"text/plain">>}]),
|
[{<<"content-type">>, <<"text/plain">>}]),
|
||||||
|
@ -230,6 +256,9 @@ set_options_idle_timeout_only_applies_to_current_request(Config) ->
|
||||||
ok
|
ok
|
||||||
after 2000 ->
|
after 2000 ->
|
||||||
error(timeout)
|
error(timeout)
|
||||||
|
end
|
||||||
|
after
|
||||||
|
cowboy:stop_listener(?FUNCTION_NAME)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
switch_protocol_flush(Config) ->
|
switch_protocol_flush(Config) ->
|
||||||
|
@ -240,6 +269,7 @@ switch_protocol_flush(Config) ->
|
||||||
},
|
},
|
||||||
{ok, _} = cowboy:start_clear(?FUNCTION_NAME, [{port, 0}], ProtoOpts),
|
{ok, _} = cowboy:start_clear(?FUNCTION_NAME, [{port, 0}], ProtoOpts),
|
||||||
Port = ranch:get_port(?FUNCTION_NAME),
|
Port = ranch:get_port(?FUNCTION_NAME),
|
||||||
|
try
|
||||||
Self = self(),
|
Self = self(),
|
||||||
ConnPid = gun_open([{port, Port}, {type, tcp}, {protocol, http}|Config]),
|
ConnPid = gun_open([{port, Port}, {type, tcp}, {protocol, http}|Config]),
|
||||||
_ = gun:get(ConnPid, "/", [
|
_ = gun:get(ConnPid, "/", [
|
||||||
|
@ -248,4 +278,9 @@ switch_protocol_flush(Config) ->
|
||||||
receive
|
receive
|
||||||
{Self, Events} ->
|
{Self, Events} ->
|
||||||
switch_protocol_flush_h:validate(Events)
|
switch_protocol_flush_h:validate(Events)
|
||||||
|
after 5000 ->
|
||||||
|
error(timeout)
|
||||||
|
end
|
||||||
|
after
|
||||||
|
cowboy:stop_listener(?FUNCTION_NAME)
|
||||||
end.
|
end.
|
||||||
|
|
|
@ -82,6 +82,7 @@ set_env(Config0) ->
|
||||||
Config = cowboy_test:init_http(?FUNCTION_NAME, #{
|
Config = cowboy_test:init_http(?FUNCTION_NAME, #{
|
||||||
env => #{dispatch => []}
|
env => #{dispatch => []}
|
||||||
}, Config0),
|
}, Config0),
|
||||||
|
try
|
||||||
ConnPid1 = gun_open(Config),
|
ConnPid1 = gun_open(Config),
|
||||||
Ref1 = gun:get(ConnPid1, "/"),
|
Ref1 = gun:get(ConnPid1, "/"),
|
||||||
{response, _, 400, _} = gun:await(ConnPid1, Ref1),
|
{response, _, 400, _} = gun:await(ConnPid1, Ref1),
|
||||||
|
@ -89,12 +90,15 @@ set_env(Config0) ->
|
||||||
%% Only new connections get the updated environment.
|
%% Only new connections get the updated environment.
|
||||||
ConnPid2 = gun_open(Config),
|
ConnPid2 = gun_open(Config),
|
||||||
Ref2 = gun:get(ConnPid2, "/"),
|
Ref2 = gun:get(ConnPid2, "/"),
|
||||||
{response, _, 200, _} = gun:await(ConnPid2, Ref2),
|
{response, _, 200, _} = gun:await(ConnPid2, Ref2)
|
||||||
ok.
|
after
|
||||||
|
cowboy:stop_listener(?FUNCTION_NAME)
|
||||||
|
end.
|
||||||
|
|
||||||
set_env_missing(Config0) ->
|
set_env_missing(Config0) ->
|
||||||
doc("Live replace a middleware environment value when env was not provided."),
|
doc("Live replace a middleware environment value when env was not provided."),
|
||||||
Config = cowboy_test:init_http(?FUNCTION_NAME, #{}, Config0),
|
Config = cowboy_test:init_http(?FUNCTION_NAME, #{}, Config0),
|
||||||
|
try
|
||||||
ConnPid1 = gun_open(Config),
|
ConnPid1 = gun_open(Config),
|
||||||
Ref1 = gun:get(ConnPid1, "/"),
|
Ref1 = gun:get(ConnPid1, "/"),
|
||||||
{response, _, 500, _} = gun:await(ConnPid1, Ref1),
|
{response, _, 500, _} = gun:await(ConnPid1, Ref1),
|
||||||
|
@ -102,5 +106,7 @@ set_env_missing(Config0) ->
|
||||||
%% Only new connections get the updated environment.
|
%% Only new connections get the updated environment.
|
||||||
ConnPid2 = gun_open(Config),
|
ConnPid2 = gun_open(Config),
|
||||||
Ref2 = gun:get(ConnPid2, "/"),
|
Ref2 = gun:get(ConnPid2, "/"),
|
||||||
{response, _, 400, _} = gun:await(ConnPid2, Ref2),
|
{response, _, 400, _} = gun:await(ConnPid2, Ref2)
|
||||||
ok.
|
after
|
||||||
|
cowboy:stop_listener(?FUNCTION_NAME)
|
||||||
|
end.
|
||||||
|
|
|
@ -1593,6 +1593,7 @@ empty_host(Config0) ->
|
||||||
Config = cowboy_test:init_http(?FUNCTION_NAME, #{
|
Config = cowboy_test:init_http(?FUNCTION_NAME, #{
|
||||||
env => #{dispatch => cowboy_router:compile(Routes)}
|
env => #{dispatch => cowboy_router:compile(Routes)}
|
||||||
}, Config0),
|
}, Config0),
|
||||||
|
try
|
||||||
#{code := 200, body := <<>>} = do_raw(Config, [
|
#{code := 200, body := <<>>} = do_raw(Config, [
|
||||||
"GET /echo/host HTTP/1.1\r\n"
|
"GET /echo/host HTTP/1.1\r\n"
|
||||||
"Host:\r\n"
|
"Host:\r\n"
|
||||||
|
@ -1600,8 +1601,10 @@ empty_host(Config0) ->
|
||||||
#{code := 200, body := <<>>} = do_raw(Config, [
|
#{code := 200, body := <<>>} = do_raw(Config, [
|
||||||
"GET /echo/host HTTP/1.1\r\n"
|
"GET /echo/host HTTP/1.1\r\n"
|
||||||
"Host: \r\n"
|
"Host: \r\n"
|
||||||
"\r\n"]),
|
"\r\n"])
|
||||||
cowboy:stop_listener(?FUNCTION_NAME).
|
after
|
||||||
|
cowboy:stop_listener(?FUNCTION_NAME)
|
||||||
|
end.
|
||||||
|
|
||||||
%% The effective request URI can be rebuilt by concatenating scheme,
|
%% The effective request URI can be rebuilt by concatenating scheme,
|
||||||
%% "://", authority, path and query components. (RFC7230 5.5)
|
%% "://", authority, path and query components. (RFC7230 5.5)
|
||||||
|
|
|
@ -1327,6 +1327,7 @@ max_frame_size_allow_exactly_custom(Config0) ->
|
||||||
env => #{dispatch => cowboy_router:compile(init_routes(Config0))},
|
env => #{dispatch => cowboy_router:compile(init_routes(Config0))},
|
||||||
max_frame_size_received => 30000
|
max_frame_size_received => 30000
|
||||||
}, Config0),
|
}, Config0),
|
||||||
|
try
|
||||||
%% Do the handshake.
|
%% Do the handshake.
|
||||||
{ok, Socket} = do_handshake(Config),
|
{ok, Socket} = do_handshake(Config),
|
||||||
%% Send a HEADERS frame initiating a stream followed by
|
%% Send a HEADERS frame initiating a stream followed by
|
||||||
|
@ -1346,8 +1347,10 @@ max_frame_size_allow_exactly_custom(Config0) ->
|
||||||
{ok, << Len2:24, 1:8, _:40 >>} = gen_tcp:recv(Socket, 9, 6000),
|
{ok, << Len2:24, 1:8, _:40 >>} = gen_tcp:recv(Socket, 9, 6000),
|
||||||
{ok, _} = gen_tcp:recv(Socket, Len2, 6000),
|
{ok, _} = gen_tcp:recv(Socket, Len2, 6000),
|
||||||
%% No errors follow due to our sending of a 25000 bytes frame.
|
%% No errors follow due to our sending of a 25000 bytes frame.
|
||||||
{error, timeout} = gen_tcp:recv(Socket, 0, 1000),
|
{error, timeout} = gen_tcp:recv(Socket, 0, 1000)
|
||||||
cowboy:stop_listener(?FUNCTION_NAME).
|
after
|
||||||
|
cowboy:stop_listener(?FUNCTION_NAME)
|
||||||
|
end.
|
||||||
|
|
||||||
max_frame_size_reject_larger_than_custom(Config0) ->
|
max_frame_size_reject_larger_than_custom(Config0) ->
|
||||||
doc("An endpoint that sets SETTINGS_MAX_FRAME_SIZE must reject frames "
|
doc("An endpoint that sets SETTINGS_MAX_FRAME_SIZE must reject frames "
|
||||||
|
@ -1357,6 +1360,7 @@ max_frame_size_reject_larger_than_custom(Config0) ->
|
||||||
env => #{dispatch => cowboy_router:compile(init_routes(Config0))},
|
env => #{dispatch => cowboy_router:compile(init_routes(Config0))},
|
||||||
max_frame_size_received => 30000
|
max_frame_size_received => 30000
|
||||||
}, Config0),
|
}, Config0),
|
||||||
|
try
|
||||||
%% Do the handshake.
|
%% Do the handshake.
|
||||||
{ok, Socket} = do_handshake(Config),
|
{ok, Socket} = do_handshake(Config),
|
||||||
%% Send a HEADERS frame initiating a stream followed by
|
%% Send a HEADERS frame initiating a stream followed by
|
||||||
|
@ -1373,8 +1377,10 @@ max_frame_size_reject_larger_than_custom(Config0) ->
|
||||||
cow_http2:data(1, fin, <<0:30001/unit:8>>)
|
cow_http2:data(1, fin, <<0:30001/unit:8>>)
|
||||||
]),
|
]),
|
||||||
%% Receive a FRAME_SIZE_ERROR connection error.
|
%% Receive a FRAME_SIZE_ERROR connection error.
|
||||||
{ok, << _:24, 7:8, _:72, 6:32 >>} = gen_tcp:recv(Socket, 17, 6000),
|
{ok, << _:24, 7:8, _:72, 6:32 >>} = gen_tcp:recv(Socket, 17, 6000)
|
||||||
cowboy:stop_listener(?FUNCTION_NAME).
|
after
|
||||||
|
cowboy:stop_listener(?FUNCTION_NAME)
|
||||||
|
end.
|
||||||
|
|
||||||
%% I am using FRAME_SIZE_ERROR here because the information in the
|
%% I am using FRAME_SIZE_ERROR here because the information in the
|
||||||
%% frame header tells us this frame is at least 1 byte long, while
|
%% frame header tells us this frame is at least 1 byte long, while
|
||||||
|
@ -2555,6 +2561,7 @@ settings_header_table_size_server(Config0) ->
|
||||||
env => #{dispatch => cowboy_router:compile(init_routes(Config0))},
|
env => #{dispatch => cowboy_router:compile(init_routes(Config0))},
|
||||||
max_decode_table_size => HeaderTableSize
|
max_decode_table_size => HeaderTableSize
|
||||||
}, Config0),
|
}, Config0),
|
||||||
|
try
|
||||||
%% Do the handhsake.
|
%% Do the handhsake.
|
||||||
{ok, Socket} = gen_tcp:connect("localhost", config(port, Config), [binary, {active, false}]),
|
{ok, Socket} = gen_tcp:connect("localhost", config(port, Config), [binary, {active, false}]),
|
||||||
%% Send a valid preface.
|
%% Send a valid preface.
|
||||||
|
@ -2585,10 +2592,12 @@ settings_header_table_size_server(Config0) ->
|
||||||
{ok, << Len1:24, 1:8, _:40 >>} = gen_tcp:recv(Socket, 9, 6000),
|
{ok, << Len1:24, 1:8, _:40 >>} = gen_tcp:recv(Socket, 9, 6000),
|
||||||
{ok, RespHeadersBlock1} = gen_tcp:recv(Socket, Len1, 6000),
|
{ok, RespHeadersBlock1} = gen_tcp:recv(Socket, Len1, 6000),
|
||||||
{RespHeaders, _} = cow_hpack:decode(RespHeadersBlock1, DecodeState),
|
{RespHeaders, _} = cow_hpack:decode(RespHeadersBlock1, DecodeState),
|
||||||
{_, <<"200">>} = lists:keyfind(<<":status">>, 1, RespHeaders),
|
{_, <<"200">>} = lists:keyfind(<<":status">>, 1, RespHeaders)
|
||||||
%% The decoding succeeded on the server, confirming that
|
%% The decoding succeeded on the server, confirming that
|
||||||
%% the table size was updated to HeaderTableSize.
|
%% the table size was updated to HeaderTableSize.
|
||||||
cowboy:stop_listener(?FUNCTION_NAME).
|
after
|
||||||
|
cowboy:stop_listener(?FUNCTION_NAME)
|
||||||
|
end.
|
||||||
|
|
||||||
settings_max_concurrent_streams(Config0) ->
|
settings_max_concurrent_streams(Config0) ->
|
||||||
doc("The SETTINGS_MAX_CONCURRENT_STREAMS setting can be used to "
|
doc("The SETTINGS_MAX_CONCURRENT_STREAMS setting can be used to "
|
||||||
|
@ -2598,6 +2607,7 @@ settings_max_concurrent_streams(Config0) ->
|
||||||
env => #{dispatch => cowboy_router:compile(init_routes(Config0))},
|
env => #{dispatch => cowboy_router:compile(init_routes(Config0))},
|
||||||
max_concurrent_streams => 1
|
max_concurrent_streams => 1
|
||||||
}, Config0),
|
}, Config0),
|
||||||
|
try
|
||||||
{ok, Socket} = do_handshake(Config),
|
{ok, Socket} = do_handshake(Config),
|
||||||
%% Send two HEADERS frames as two separate streams.
|
%% Send two HEADERS frames as two separate streams.
|
||||||
Headers = [
|
Headers = [
|
||||||
|
@ -2613,8 +2623,10 @@ settings_max_concurrent_streams(Config0) ->
|
||||||
cow_http2:headers(3, fin, ReqHeadersBlock2)
|
cow_http2:headers(3, fin, ReqHeadersBlock2)
|
||||||
]),
|
]),
|
||||||
%% Receive a REFUSED_STREAM stream error.
|
%% Receive a REFUSED_STREAM stream error.
|
||||||
{ok, << _:24, 3:8, _:8, 3:32, 7:32 >>} = gen_tcp:recv(Socket, 13, 6000),
|
{ok, << _:24, 3:8, _:8, 3:32, 7:32 >>} = gen_tcp:recv(Socket, 13, 6000)
|
||||||
cowboy:stop_listener(?FUNCTION_NAME).
|
after
|
||||||
|
cowboy:stop_listener(?FUNCTION_NAME)
|
||||||
|
end.
|
||||||
|
|
||||||
settings_max_concurrent_streams_0(Config0) ->
|
settings_max_concurrent_streams_0(Config0) ->
|
||||||
doc("The SETTINGS_MAX_CONCURRENT_STREAMS setting can be set to "
|
doc("The SETTINGS_MAX_CONCURRENT_STREAMS setting can be set to "
|
||||||
|
@ -2624,6 +2636,7 @@ settings_max_concurrent_streams_0(Config0) ->
|
||||||
env => #{dispatch => cowboy_router:compile(init_routes(Config0))},
|
env => #{dispatch => cowboy_router:compile(init_routes(Config0))},
|
||||||
max_concurrent_streams => 0
|
max_concurrent_streams => 0
|
||||||
}, Config0),
|
}, Config0),
|
||||||
|
try
|
||||||
{ok, Socket} = do_handshake(Config),
|
{ok, Socket} = do_handshake(Config),
|
||||||
%% Send a HEADERS frame.
|
%% Send a HEADERS frame.
|
||||||
{HeadersBlock, _} = cow_hpack:encode([
|
{HeadersBlock, _} = cow_hpack:encode([
|
||||||
|
@ -2634,8 +2647,10 @@ settings_max_concurrent_streams_0(Config0) ->
|
||||||
]),
|
]),
|
||||||
ok = gen_tcp:send(Socket, cow_http2:headers(1, fin, HeadersBlock)),
|
ok = gen_tcp:send(Socket, cow_http2:headers(1, fin, HeadersBlock)),
|
||||||
%% Receive a REFUSED_STREAM stream error.
|
%% Receive a REFUSED_STREAM stream error.
|
||||||
{ok, << _:24, 3:8, _:8, 1:32, 7:32 >>} = gen_tcp:recv(Socket, 13, 6000),
|
{ok, << _:24, 3:8, _:8, 1:32, 7:32 >>} = gen_tcp:recv(Socket, 13, 6000)
|
||||||
cowboy:stop_listener(?FUNCTION_NAME).
|
after
|
||||||
|
cowboy:stop_listener(?FUNCTION_NAME)
|
||||||
|
end.
|
||||||
|
|
||||||
%% @todo The client can limit the number of concurrent streams too. (RFC7540 5.1.2)
|
%% @todo The client can limit the number of concurrent streams too. (RFC7540 5.1.2)
|
||||||
%
|
%
|
||||||
|
@ -2663,6 +2678,7 @@ settings_initial_window_size(Config0) ->
|
||||||
initial_connection_window_size => 100000,
|
initial_connection_window_size => 100000,
|
||||||
initial_stream_window_size => 100000
|
initial_stream_window_size => 100000
|
||||||
}, Config0),
|
}, Config0),
|
||||||
|
try
|
||||||
%% We need to do the handshake manually because a WINDOW_UPDATE
|
%% We need to do the handshake manually because a WINDOW_UPDATE
|
||||||
%% frame will be sent to update the connection window.
|
%% frame will be sent to update the connection window.
|
||||||
{ok, Socket} = gen_tcp:connect("localhost", config(port, Config), [binary, {active, false}]),
|
{ok, Socket} = gen_tcp:connect("localhost", config(port, Config), [binary, {active, false}]),
|
||||||
|
@ -2699,8 +2715,10 @@ settings_initial_window_size(Config0) ->
|
||||||
{ok, << Len2:24, 1:8, _:40 >>} = gen_tcp:recv(Socket, 9, 6000),
|
{ok, << Len2:24, 1:8, _:40 >>} = gen_tcp:recv(Socket, 9, 6000),
|
||||||
{ok, _} = gen_tcp:recv(Socket, Len2, 6000),
|
{ok, _} = gen_tcp:recv(Socket, Len2, 6000),
|
||||||
%% No errors follow due to our sending of more than 65535 bytes of data.
|
%% No errors follow due to our sending of more than 65535 bytes of data.
|
||||||
{error, timeout} = gen_tcp:recv(Socket, 0, 1000),
|
{error, timeout} = gen_tcp:recv(Socket, 0, 1000)
|
||||||
cowboy:stop_listener(?FUNCTION_NAME).
|
after
|
||||||
|
cowboy:stop_listener(?FUNCTION_NAME)
|
||||||
|
end.
|
||||||
|
|
||||||
settings_initial_window_size_after_ack(Config0) ->
|
settings_initial_window_size_after_ack(Config0) ->
|
||||||
doc("The SETTINGS_INITIAL_WINDOW_SIZE setting can be used to "
|
doc("The SETTINGS_INITIAL_WINDOW_SIZE setting can be used to "
|
||||||
|
@ -2711,6 +2729,7 @@ settings_initial_window_size_after_ack(Config0) ->
|
||||||
env => #{dispatch => cowboy_router:compile(init_routes(Config0))},
|
env => #{dispatch => cowboy_router:compile(init_routes(Config0))},
|
||||||
initial_stream_window_size => 0
|
initial_stream_window_size => 0
|
||||||
}, Config0),
|
}, Config0),
|
||||||
|
try
|
||||||
%% We need to do the handshake manually because we don't
|
%% We need to do the handshake manually because we don't
|
||||||
%% want to send the SETTINGS ack immediately.
|
%% want to send the SETTINGS ack immediately.
|
||||||
{ok, Socket} = gen_tcp:connect("localhost", config(port, Config), [binary, {active, false}]),
|
{ok, Socket} = gen_tcp:connect("localhost", config(port, Config), [binary, {active, false}]),
|
||||||
|
@ -2739,8 +2758,10 @@ settings_initial_window_size_after_ack(Config0) ->
|
||||||
cow_http2:data(1, fin, <<0:32/unit:8>>)
|
cow_http2:data(1, fin, <<0:32/unit:8>>)
|
||||||
]),
|
]),
|
||||||
%% Receive a FLOW_CONTROL_ERROR stream error.
|
%% Receive a FLOW_CONTROL_ERROR stream error.
|
||||||
{ok, << _:24, 3:8, _:8, 1:32, 3:32 >>} = gen_tcp:recv(Socket, 13, 6000),
|
{ok, << _:24, 3:8, _:8, 1:32, 3:32 >>} = gen_tcp:recv(Socket, 13, 6000)
|
||||||
cowboy:stop_listener(?FUNCTION_NAME).
|
after
|
||||||
|
cowboy:stop_listener(?FUNCTION_NAME)
|
||||||
|
end.
|
||||||
|
|
||||||
settings_initial_window_size_before_ack(Config0) ->
|
settings_initial_window_size_before_ack(Config0) ->
|
||||||
doc("The SETTINGS_INITIAL_WINDOW_SIZE setting can be used to "
|
doc("The SETTINGS_INITIAL_WINDOW_SIZE setting can be used to "
|
||||||
|
@ -2751,6 +2772,7 @@ settings_initial_window_size_before_ack(Config0) ->
|
||||||
env => #{dispatch => cowboy_router:compile(init_routes(Config0))},
|
env => #{dispatch => cowboy_router:compile(init_routes(Config0))},
|
||||||
initial_stream_window_size => 0
|
initial_stream_window_size => 0
|
||||||
}, Config0),
|
}, Config0),
|
||||||
|
try
|
||||||
%% We need to do the handshake manually because we don't
|
%% We need to do the handshake manually because we don't
|
||||||
%% want to send the SETTINGS ack.
|
%% want to send the SETTINGS ack.
|
||||||
{ok, Socket} = gen_tcp:connect("localhost", config(port, Config), [binary, {active, false}]),
|
{ok, Socket} = gen_tcp:connect("localhost", config(port, Config), [binary, {active, false}]),
|
||||||
|
@ -2784,8 +2806,10 @@ settings_initial_window_size_before_ack(Config0) ->
|
||||||
{ok, << Len2:24, 1:8, _:40 >>} = gen_tcp:recv(Socket, 9, 6000),
|
{ok, << Len2:24, 1:8, _:40 >>} = gen_tcp:recv(Socket, 9, 6000),
|
||||||
{ok, _} = gen_tcp:recv(Socket, Len2, 6000),
|
{ok, _} = gen_tcp:recv(Socket, Len2, 6000),
|
||||||
%% No errors follow due to our sending of more than 0 bytes of data.
|
%% No errors follow due to our sending of more than 0 bytes of data.
|
||||||
{error, timeout} = gen_tcp:recv(Socket, 0, 1000),
|
{error, timeout} = gen_tcp:recv(Socket, 0, 1000)
|
||||||
cowboy:stop_listener(?FUNCTION_NAME).
|
after
|
||||||
|
cowboy:stop_listener(?FUNCTION_NAME)
|
||||||
|
end.
|
||||||
|
|
||||||
settings_max_frame_size(Config0) ->
|
settings_max_frame_size(Config0) ->
|
||||||
doc("The SETTINGS_MAX_FRAME_SIZE setting can be used to "
|
doc("The SETTINGS_MAX_FRAME_SIZE setting can be used to "
|
||||||
|
@ -2795,6 +2819,7 @@ settings_max_frame_size(Config0) ->
|
||||||
env => #{dispatch => cowboy_router:compile(init_routes(Config0))},
|
env => #{dispatch => cowboy_router:compile(init_routes(Config0))},
|
||||||
max_frame_size_received => 30000
|
max_frame_size_received => 30000
|
||||||
}, Config0),
|
}, Config0),
|
||||||
|
try
|
||||||
%% Do the handshake.
|
%% Do the handshake.
|
||||||
{ok, Socket} = do_handshake(Config),
|
{ok, Socket} = do_handshake(Config),
|
||||||
%% Send a HEADERS frame initiating a stream followed by
|
%% Send a HEADERS frame initiating a stream followed by
|
||||||
|
@ -2814,8 +2839,10 @@ settings_max_frame_size(Config0) ->
|
||||||
{ok, << Len2:24, 1:8, _:40 >>} = gen_tcp:recv(Socket, 9, 6000),
|
{ok, << Len2:24, 1:8, _:40 >>} = gen_tcp:recv(Socket, 9, 6000),
|
||||||
{ok, _} = gen_tcp:recv(Socket, Len2, 6000),
|
{ok, _} = gen_tcp:recv(Socket, Len2, 6000),
|
||||||
%% No errors follow due to our sending of a 25000 bytes frame.
|
%% No errors follow due to our sending of a 25000 bytes frame.
|
||||||
{error, timeout} = gen_tcp:recv(Socket, 0, 1000),
|
{error, timeout} = gen_tcp:recv(Socket, 0, 1000)
|
||||||
cowboy:stop_listener(?FUNCTION_NAME).
|
after
|
||||||
|
cowboy:stop_listener(?FUNCTION_NAME)
|
||||||
|
end.
|
||||||
|
|
||||||
settings_max_frame_size_reject_too_small(Config) ->
|
settings_max_frame_size_reject_too_small(Config) ->
|
||||||
doc("A SETTINGS_MAX_FRAME_SIZE smaller than 16384 must be rejected "
|
doc("A SETTINGS_MAX_FRAME_SIZE smaller than 16384 must be rejected "
|
||||||
|
@ -3015,6 +3042,7 @@ data_reject_overflow(Config0) ->
|
||||||
env => #{dispatch => cowboy_router:compile(init_routes(Config0))},
|
env => #{dispatch => cowboy_router:compile(init_routes(Config0))},
|
||||||
initial_stream_window_size => 100000
|
initial_stream_window_size => 100000
|
||||||
}, Config0),
|
}, Config0),
|
||||||
|
try
|
||||||
{ok, Socket} = do_handshake(Config),
|
{ok, Socket} = do_handshake(Config),
|
||||||
%% Send a HEADERS frame initiating a stream followed by
|
%% Send a HEADERS frame initiating a stream followed by
|
||||||
%% DATA frames totaling 90000 bytes of body.
|
%% DATA frames totaling 90000 bytes of body.
|
||||||
|
@ -3035,8 +3063,10 @@ data_reject_overflow(Config0) ->
|
||||||
cow_http2:data(1, fin, <<0:15000/unit:8>>)
|
cow_http2:data(1, fin, <<0:15000/unit:8>>)
|
||||||
]),
|
]),
|
||||||
%% Receive a FLOW_CONTROL_ERROR connection error.
|
%% Receive a FLOW_CONTROL_ERROR connection error.
|
||||||
{ok, << _:24, 7:8, _:72, 3:32 >>} = gen_tcp:recv(Socket, 17, 6000),
|
{ok, << _:24, 7:8, _:72, 3:32 >>} = gen_tcp:recv(Socket, 17, 6000)
|
||||||
cowboy:stop_listener(?FUNCTION_NAME).
|
after
|
||||||
|
cowboy:stop_listener(?FUNCTION_NAME)
|
||||||
|
end.
|
||||||
|
|
||||||
data_reject_overflow_stream(Config0) ->
|
data_reject_overflow_stream(Config0) ->
|
||||||
doc("DATA frames that cause the stream flow control window "
|
doc("DATA frames that cause the stream flow control window "
|
||||||
|
@ -3047,6 +3077,7 @@ data_reject_overflow_stream(Config0) ->
|
||||||
env => #{dispatch => cowboy_router:compile(init_routes(Config0))},
|
env => #{dispatch => cowboy_router:compile(init_routes(Config0))},
|
||||||
initial_connection_window_size => 100000
|
initial_connection_window_size => 100000
|
||||||
}, Config0),
|
}, Config0),
|
||||||
|
try
|
||||||
%% We need to do the handshake manually because a WINDOW_UPDATE
|
%% We need to do the handshake manually because a WINDOW_UPDATE
|
||||||
%% frame will be sent to update the connection window.
|
%% frame will be sent to update the connection window.
|
||||||
{ok, Socket} = gen_tcp:connect("localhost", config(port, Config), [binary, {active, false}]),
|
{ok, Socket} = gen_tcp:connect("localhost", config(port, Config), [binary, {active, false}]),
|
||||||
|
@ -3080,8 +3111,10 @@ data_reject_overflow_stream(Config0) ->
|
||||||
cow_http2:data(1, fin, <<0:15000/unit:8>>)
|
cow_http2:data(1, fin, <<0:15000/unit:8>>)
|
||||||
]),
|
]),
|
||||||
%% Receive a FLOW_CONTROL_ERROR stream error.
|
%% Receive a FLOW_CONTROL_ERROR stream error.
|
||||||
{ok, << _:24, 3:8, _:8, 1:32, 3:32 >>} = gen_tcp:recv(Socket, 13, 6000),
|
{ok, << _:24, 3:8, _:8, 1:32, 3:32 >>} = gen_tcp:recv(Socket, 13, 6000)
|
||||||
cowboy:stop_listener(?FUNCTION_NAME).
|
after
|
||||||
|
cowboy:stop_listener(?FUNCTION_NAME)
|
||||||
|
end.
|
||||||
|
|
||||||
%% (RFC7540 6.9.1)
|
%% (RFC7540 6.9.1)
|
||||||
% Frames with zero length with the END_STREAM flag set (that
|
% Frames with zero length with the END_STREAM flag set (that
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue