mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 12:20:24 +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),
|
||||||
{ok, Socket} = do_handshake([{port, Port}|Config]),
|
try
|
||||||
timer:sleep(1000),
|
{ok, Socket} = do_handshake([{port, Port}|Config]),
|
||||||
%% Receive a GOAWAY frame back with NO_ERROR.
|
timer:sleep(1000),
|
||||||
{ok, << _:24, 7:8, _:72, 0:32 >>} = gen_tcp:recv(Socket, 17, 1000),
|
%% Receive a GOAWAY frame back with NO_ERROR.
|
||||||
ok.
|
{ok, << _:24, 7:8, _:72, 0:32 >>} = gen_tcp:recv(Socket, 17, 1000)
|
||||||
|
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),
|
||||||
{ok, Socket} = do_handshake([{port, Port}|Config]),
|
try
|
||||||
timer:sleep(1000),
|
{ok, Socket} = do_handshake([{port, Port}|Config]),
|
||||||
%% Don't receive a GOAWAY frame.
|
timer:sleep(1000),
|
||||||
{error, timeout} = gen_tcp:recv(Socket, 17, 1000),
|
%% Don't receive a GOAWAY frame.
|
||||||
ok.
|
{error, timeout} = gen_tcp:recv(Socket, 17, 1000)
|
||||||
|
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,23 +92,26 @@ 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),
|
||||||
{ok, Socket} = do_handshake([{port, Port}|Config]),
|
try
|
||||||
%% We wait a little, send a PING, receive a PING ack.
|
{ok, Socket} = do_handshake([{port, Port}|Config]),
|
||||||
{error, timeout} = gen_tcp:recv(Socket, 17, 500),
|
%% We wait a little, send a PING, receive a PING ack.
|
||||||
ok = gen_tcp:send(Socket, cow_http2:ping(0)),
|
{error, timeout} = gen_tcp:recv(Socket, 17, 500),
|
||||||
{ok, <<8:24, 6:8, 0:7, 1:1, 0:96>>} = gen_tcp:recv(Socket, 17, 1000),
|
ok = gen_tcp:send(Socket, cow_http2:ping(0)),
|
||||||
%% Again.
|
{ok, <<8:24, 6:8, 0:7, 1:1, 0:96>>} = gen_tcp:recv(Socket, 17, 1000),
|
||||||
{error, timeout} = gen_tcp:recv(Socket, 17, 500),
|
%% Again.
|
||||||
ok = gen_tcp:send(Socket, cow_http2:ping(0)),
|
{error, timeout} = gen_tcp:recv(Socket, 17, 500),
|
||||||
{ok, <<8:24, 6:8, 0:7, 1:1, 0:96>>} = gen_tcp:recv(Socket, 17, 1000),
|
ok = gen_tcp:send(Socket, cow_http2:ping(0)),
|
||||||
%% And one more time.
|
{ok, <<8:24, 6:8, 0:7, 1:1, 0:96>>} = gen_tcp:recv(Socket, 17, 1000),
|
||||||
{error, timeout} = gen_tcp:recv(Socket, 17, 500),
|
%% And one more time.
|
||||||
ok = gen_tcp:send(Socket, cow_http2:ping(0)),
|
{error, timeout} = gen_tcp:recv(Socket, 17, 500),
|
||||||
{ok, <<8:24, 6:8, 0:7, 1:1, 0:96>>} = gen_tcp:recv(Socket, 17, 1000),
|
ok = gen_tcp:send(Socket, cow_http2:ping(0)),
|
||||||
%% The connection goes away soon after we stop sending data.
|
{ok, <<8:24, 6:8, 0:7, 1:1, 0:96>>} = gen_tcp:recv(Socket, 17, 1000),
|
||||||
timer:sleep(1000),
|
%% The connection goes away soon after we stop sending data.
|
||||||
{ok, << _:24, 7:8, _:72, 0:32 >>} = gen_tcp:recv(Socket, 17, 1000),
|
timer:sleep(1000),
|
||||||
ok.
|
{ok, << _:24, 7:8, _:72, 0:32 >>} = gen_tcp:recv(Socket, 17, 1000)
|
||||||
|
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),
|
||||||
{ok, Socket} = do_handshake([{port, Port}|Config]),
|
try
|
||||||
receive after 1000 -> ok end,
|
{ok, Socket} = do_handshake([{port, Port}|Config]),
|
||||||
%% Receive a GOAWAY frame back with an INTERNAL_ERROR.
|
receive after 1000 -> ok end,
|
||||||
{ok, << _:24, 7:8, _:72, 2:32 >>} = gen_tcp:recv(Socket, 17, 1000),
|
%% Receive a GOAWAY frame back with an INTERNAL_ERROR.
|
||||||
ok.
|
{ok, << _:24, 7:8, _:72, 2:32 >>} = gen_tcp:recv(Socket, 17, 1000)
|
||||||
|
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,16 +140,19 @@ 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),
|
||||||
{ok, Socket} = gen_tcp:connect("localhost", Port, [binary, {active, false}]),
|
try
|
||||||
%% Send a valid preface.
|
{ok, Socket} = gen_tcp:connect("localhost", Port, [binary, {active, false}]),
|
||||||
ok = gen_tcp:send(Socket, ["PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n", cow_http2:settings(#{})]),
|
%% Send a valid preface.
|
||||||
%% Receive the server preface.
|
ok = gen_tcp:send(Socket, ["PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n", cow_http2:settings(#{})]),
|
||||||
{ok, << Len:24 >>} = gen_tcp:recv(Socket, 3, 1000),
|
%% Receive the server preface.
|
||||||
{ok, << 4:8, 0:40, _:Len/binary >>} = gen_tcp:recv(Socket, 6 + Len, 1000),
|
{ok, << Len:24 >>} = gen_tcp:recv(Socket, 3, 1000),
|
||||||
%% Receive a WINDOW_UPDATE frame incrementing the connection window to 100000.
|
{ok, << 4:8, 0:40, _:Len/binary >>} = gen_tcp:recv(Socket, 6 + Len, 1000),
|
||||||
{ok, <<4:24, 8:8, 0:41, Size:31>>} = gen_tcp:recv(Socket, 13, 1000),
|
%% Receive a WINDOW_UPDATE frame incrementing the connection window to 100000.
|
||||||
ConfiguredSize = Size + 65535,
|
{ok, <<4:24, 8:8, 0:41, Size:31>>} = gen_tcp:recv(Socket, 13, 1000),
|
||||||
ok.
|
ConfiguredSize = Size + 65535
|
||||||
|
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,35 +164,38 @@ 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
|
||||||
%% Send a request with a 30000 bytes body.
|
{ok, Socket} = do_handshake(#{max_frame_size => MaxFrameSize + 10000},
|
||||||
{HeadersBlock, _} = cow_hpack:encode([
|
[{port, Port}|Config]),
|
||||||
{<<":method">>, <<"POST">>},
|
%% Send a request with a 30000 bytes body.
|
||||||
{<<":scheme">>, <<"http">>},
|
{HeadersBlock, _} = cow_hpack:encode([
|
||||||
{<<":authority">>, <<"localhost">>}, %% @todo Correct port number.
|
{<<":method">>, <<"POST">>},
|
||||||
{<<":path">>, <<"/echo/read_body">>}
|
{<<":scheme">>, <<"http">>},
|
||||||
]),
|
{<<":authority">>, <<"localhost">>}, %% @todo Correct port number.
|
||||||
ok = gen_tcp:send(Socket, [
|
{<<":path">>, <<"/echo/read_body">>}
|
||||||
cow_http2:headers(1, nofin, HeadersBlock),
|
]),
|
||||||
cow_http2:data(1, nofin, <<0:16384/unit:8>>),
|
ok = gen_tcp:send(Socket, [
|
||||||
cow_http2:data(1, fin, <<0:13616/unit:8>>)
|
cow_http2:headers(1, nofin, HeadersBlock),
|
||||||
]),
|
cow_http2:data(1, nofin, <<0:16384/unit:8>>),
|
||||||
%% Receive a HEADERS frame as a response.
|
cow_http2:data(1, fin, <<0:13616/unit:8>>)
|
||||||
{ok, << SkipLen:24, 1:8, _:8, 1:32 >>} = case gen_tcp:recv(Socket, 9, 1000) of
|
]),
|
||||||
%% We received a WINDOW_UPDATE first. Skip it and the next.
|
%% Receive a HEADERS frame as a response.
|
||||||
{ok, <<4:24, 8:8, 0:40>>} ->
|
{ok, << SkipLen:24, 1:8, _:8, 1:32 >>} = case gen_tcp:recv(Socket, 9, 1000) of
|
||||||
{ok, _} = gen_tcp:recv(Socket, 4 + 13, 1000),
|
%% We received a WINDOW_UPDATE first. Skip it and the next.
|
||||||
gen_tcp:recv(Socket, 9, 1000);
|
{ok, <<4:24, 8:8, 0:40>>} ->
|
||||||
Res ->
|
{ok, _} = gen_tcp:recv(Socket, 4 + 13, 1000),
|
||||||
Res
|
gen_tcp:recv(Socket, 9, 1000);
|
||||||
end,
|
Res ->
|
||||||
{ok, _} = gen_tcp:recv(Socket, SkipLen, 6000),
|
Res
|
||||||
%% The DATA frames following must have lengths of 20000
|
end,
|
||||||
%% and then 10000 due to the limit.
|
{ok, _} = gen_tcp:recv(Socket, SkipLen, 6000),
|
||||||
{ok, <<20000:24, 0:8, _:40, _:20000/unit:8>>} = gen_tcp:recv(Socket, 20009, 6000),
|
%% The DATA frames following must have lengths of 20000
|
||||||
{ok, <<10000:24, 0:8, _:40, _:10000/unit:8>>} = gen_tcp:recv(Socket, 10009, 6000),
|
%% and then 10000 due to the limit.
|
||||||
%% Stop the listener.
|
{ok, <<20000:24, 0:8, _:40, _:20000/unit:8>>} = gen_tcp:recv(Socket, 20009, 6000),
|
||||||
cowboy:stop_listener(?FUNCTION_NAME).
|
{ok, <<10000:24, 0:8, _:40, _:10000/unit:8>>} = gen_tcp:recv(Socket, 10009, 6000)
|
||||||
|
after
|
||||||
|
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,13 +205,17 @@ 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),
|
||||||
{ok, Socket} = do_handshake([{port, Port}|Config]),
|
try
|
||||||
Pid = get_remote_pid_tcp(Socket),
|
{ok, Socket} = do_handshake([{port, Port}|Config]),
|
||||||
Ref = erlang:monitor(process, Pid),
|
Pid = get_remote_pid_tcp(Socket),
|
||||||
receive
|
Ref = erlang:monitor(process, Pid),
|
||||||
{'DOWN', Ref, process, Pid, Reason} ->
|
receive
|
||||||
error(Reason)
|
{'DOWN', Ref, process, Pid, Reason} ->
|
||||||
after 1000 ->
|
error(Reason)
|
||||||
|
after 1000 ->
|
||||||
|
ok
|
||||||
|
end
|
||||||
|
after
|
||||||
cowboy:stop_listener(?FUNCTION_NAME)
|
cowboy:stop_listener(?FUNCTION_NAME)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -206,14 +228,18 @@ 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),
|
||||||
ConnPid = gun_open([{type, tcp}, {protocol, http2}, {port, Port}|Config]),
|
try
|
||||||
Ref = gun:get(ConnPid, "/resp_iolist_body"),
|
ConnPid = gun_open([{type, tcp}, {protocol, http2}, {port, Port}|Config]),
|
||||||
{response, nofin, 200, RespHeaders} = gun:await(ConnPid, Ref),
|
Ref = gun:get(ConnPid, "/resp_iolist_body"),
|
||||||
{_, BinLen} = lists:keyfind(<<"content-length">>, 1, RespHeaders),
|
{response, nofin, 200, RespHeaders} = gun:await(ConnPid, Ref),
|
||||||
Len = binary_to_integer(BinLen),
|
{_, BinLen} = lists:keyfind(<<"content-length">>, 1, RespHeaders),
|
||||||
{ok, RespBody} = gun:await_body(ConnPid, Ref),
|
Len = binary_to_integer(BinLen),
|
||||||
Len = iolist_size(RespBody),
|
{ok, RespBody} = gun:await_body(ConnPid, Ref),
|
||||||
gun:close(ConnPid).
|
Len = iolist_size(RespBody),
|
||||||
|
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,12 +249,16 @@ 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),
|
||||||
{ok, Socket} = do_handshake([{port, Port}|Config]),
|
try
|
||||||
Pid = get_remote_pid_tcp(Socket),
|
{ok, Socket} = do_handshake([{port, Port}|Config]),
|
||||||
Ref = erlang:monitor(process, Pid),
|
Pid = get_remote_pid_tcp(Socket),
|
||||||
receive
|
Ref = erlang:monitor(process, Pid),
|
||||||
{'DOWN', Ref, process, Pid, Reason} ->
|
receive
|
||||||
error(Reason)
|
{'DOWN', Ref, process, Pid, Reason} ->
|
||||||
after 1000 ->
|
error(Reason)
|
||||||
|
after 1000 ->
|
||||||
|
ok
|
||||||
|
end
|
||||||
|
after
|
||||||
cowboy:stop_listener(?FUNCTION_NAME)
|
cowboy:stop_listener(?FUNCTION_NAME)
|
||||||
end.
|
end.
|
||||||
|
|
|
@ -47,23 +47,26 @@ chunked_false(Config) ->
|
||||||
chunked => false
|
chunked => false
|
||||||
}),
|
}),
|
||||||
Port = ranch:get_port(?FUNCTION_NAME),
|
Port = ranch:get_port(?FUNCTION_NAME),
|
||||||
Request = "GET /resp/stream_reply2/200 HTTP/1.1\r\nhost: localhost\r\n\r\n",
|
try
|
||||||
Client = raw_open([{type, tcp}, {port, Port}, {opts, []}|Config]),
|
Request = "GET /resp/stream_reply2/200 HTTP/1.1\r\nhost: localhost\r\n\r\n",
|
||||||
ok = raw_send(Client, Request),
|
Client = raw_open([{type, tcp}, {port, Port}, {opts, []}|Config]),
|
||||||
Rest = case catch raw_recv_head(Client) of
|
ok = raw_send(Client, Request),
|
||||||
{'EXIT', _} -> error(closed);
|
Rest = case catch raw_recv_head(Client) of
|
||||||
Data ->
|
{'EXIT', _} -> error(closed);
|
||||||
%% Cowboy always advertises itself as HTTP/1.1.
|
Data ->
|
||||||
{'HTTP/1.1', 200, _, Rest0} = cow_http:parse_status_line(Data),
|
%% Cowboy always advertises itself as HTTP/1.1.
|
||||||
{Headers, Rest1} = cow_http:parse_headers(Rest0),
|
{'HTTP/1.1', 200, _, Rest0} = cow_http:parse_status_line(Data),
|
||||||
false = lists:keyfind(<<"content-length">>, 1, Headers),
|
{Headers, Rest1} = cow_http:parse_headers(Rest0),
|
||||||
false = lists:keyfind(<<"transfer-encoding">>, 1, Headers),
|
false = lists:keyfind(<<"content-length">>, 1, Headers),
|
||||||
Rest1
|
false = lists:keyfind(<<"transfer-encoding">>, 1, Headers),
|
||||||
end,
|
Rest1
|
||||||
Bits = 8000000 - bit_size(Rest),
|
end,
|
||||||
raw_expect_recv(Client, <<0:Bits>>),
|
Bits = 8000000 - bit_size(Rest),
|
||||||
{error, closed} = raw_recv(Client, 1, 1000),
|
raw_expect_recv(Client, <<0:Bits>>),
|
||||||
ok.
|
{error, closed} = raw_recv(Client, 1, 1000)
|
||||||
|
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,21 +76,25 @@ http10_keepalive_false(Config) ->
|
||||||
http10_keepalive => false
|
http10_keepalive => false
|
||||||
}),
|
}),
|
||||||
Port = ranch:get_port(?FUNCTION_NAME),
|
Port = ranch:get_port(?FUNCTION_NAME),
|
||||||
Keepalive = "GET / HTTP/1.0\r\nhost: localhost\r\nConnection: keep-alive\r\n\r\n",
|
try
|
||||||
Client = raw_open([{type, tcp}, {port, Port}, {opts, []}|Config]),
|
Keepalive = "GET / HTTP/1.0\r\nhost: localhost\r\nConnection: keep-alive\r\n\r\n",
|
||||||
ok = raw_send(Client, Keepalive),
|
Client = raw_open([{type, tcp}, {port, Port}, {opts, []}|Config]),
|
||||||
_ = case catch raw_recv_head(Client) of
|
ok = raw_send(Client, Keepalive),
|
||||||
{'EXIT', _} -> error(closed);
|
_ = case catch raw_recv_head(Client) of
|
||||||
Data ->
|
{'EXIT', _} -> error(closed);
|
||||||
%% Cowboy always advertises itself as HTTP/1.1.
|
Data ->
|
||||||
{'HTTP/1.1', 200, _, Rest} = cow_http:parse_status_line(Data),
|
%% Cowboy always advertises itself as HTTP/1.1.
|
||||||
{Headers, _} = cow_http:parse_headers(Rest),
|
{'HTTP/1.1', 200, _, Rest} = cow_http:parse_status_line(Data),
|
||||||
{_, <<"close">>} = lists:keyfind(<<"connection">>, 1, Headers)
|
{Headers, _} = cow_http:parse_headers(Rest),
|
||||||
end,
|
{_, <<"close">>} = lists:keyfind(<<"connection">>, 1, Headers)
|
||||||
ok = raw_send(Client, Keepalive),
|
end,
|
||||||
case catch raw_recv_head(Client) of
|
ok = raw_send(Client, Keepalive),
|
||||||
{'EXIT', _} -> closed;
|
case catch raw_recv_head(Client) of
|
||||||
_ -> error(not_closed)
|
{'EXIT', _} -> closed;
|
||||||
|
_ -> error(not_closed)
|
||||||
|
end
|
||||||
|
after
|
||||||
|
cowboy:stop_listener(?FUNCTION_NAME)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
idle_timeout_infinity(Config) ->
|
idle_timeout_infinity(Config) ->
|
||||||
|
@ -98,17 +105,21 @@ idle_timeout_infinity(Config) ->
|
||||||
idle_timeout => infinity
|
idle_timeout => infinity
|
||||||
}),
|
}),
|
||||||
Port = ranch:get_port(?FUNCTION_NAME),
|
Port = ranch:get_port(?FUNCTION_NAME),
|
||||||
ConnPid = gun_open([{type, tcp}, {protocol, http}, {port, Port}|Config]),
|
try
|
||||||
_ = gun:post(ConnPid, "/echo/read_body",
|
ConnPid = gun_open([{type, tcp}, {protocol, http}, {port, Port}|Config]),
|
||||||
[{<<"content-type">>, <<"text/plain">>}]),
|
_ = gun:post(ConnPid, "/echo/read_body",
|
||||||
#{socket := Socket} = gun:info(ConnPid),
|
[{<<"content-type">>, <<"text/plain">>}]),
|
||||||
Pid = get_remote_pid_tcp(Socket),
|
#{socket := Socket} = gun:info(ConnPid),
|
||||||
Ref = erlang:monitor(process, Pid),
|
Pid = get_remote_pid_tcp(Socket),
|
||||||
receive
|
Ref = erlang:monitor(process, Pid),
|
||||||
{'DOWN', Ref, process, Pid, Reason} ->
|
receive
|
||||||
error(Reason)
|
{'DOWN', Ref, process, Pid, Reason} ->
|
||||||
after 1000 ->
|
error(Reason)
|
||||||
ok
|
after 1000 ->
|
||||||
|
ok
|
||||||
|
end
|
||||||
|
after
|
||||||
|
cowboy:stop_listener(?FUNCTION_NAME)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
request_timeout_infinity(Config) ->
|
request_timeout_infinity(Config) ->
|
||||||
|
@ -118,15 +129,19 @@ request_timeout_infinity(Config) ->
|
||||||
idle_timeout => infinity
|
idle_timeout => infinity
|
||||||
}),
|
}),
|
||||||
Port = ranch:get_port(?FUNCTION_NAME),
|
Port = ranch:get_port(?FUNCTION_NAME),
|
||||||
ConnPid = gun_open([{type, tcp}, {protocol, http}, {port, Port}|Config]),
|
try
|
||||||
#{socket := Socket} = gun:info(ConnPid),
|
ConnPid = gun_open([{type, tcp}, {protocol, http}, {port, Port}|Config]),
|
||||||
Pid = get_remote_pid_tcp(Socket),
|
#{socket := Socket} = gun:info(ConnPid),
|
||||||
Ref = erlang:monitor(process, Pid),
|
Pid = get_remote_pid_tcp(Socket),
|
||||||
receive
|
Ref = erlang:monitor(process, Pid),
|
||||||
{'DOWN', Ref, process, Pid, Reason} ->
|
receive
|
||||||
error(Reason)
|
{'DOWN', Ref, process, Pid, Reason} ->
|
||||||
after 1000 ->
|
error(Reason)
|
||||||
ok
|
after 1000 ->
|
||||||
|
ok
|
||||||
|
end
|
||||||
|
after
|
||||||
|
cowboy:stop_listener(?FUNCTION_NAME)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
set_options_chunked_false(Config) ->
|
set_options_chunked_false(Config) ->
|
||||||
|
@ -138,21 +153,24 @@ set_options_chunked_false(Config) ->
|
||||||
chunked => true
|
chunked => true
|
||||||
}),
|
}),
|
||||||
Port = ranch:get_port(?FUNCTION_NAME),
|
Port = ranch:get_port(?FUNCTION_NAME),
|
||||||
Request = "GET /set_options/chunked_false HTTP/1.1\r\nhost: localhost\r\n\r\n",
|
try
|
||||||
Client = raw_open([{type, tcp}, {port, Port}, {opts, []}|Config]),
|
Request = "GET /set_options/chunked_false HTTP/1.1\r\nhost: localhost\r\n\r\n",
|
||||||
ok = raw_send(Client, Request),
|
Client = raw_open([{type, tcp}, {port, Port}, {opts, []}|Config]),
|
||||||
_ = case catch raw_recv_head(Client) of
|
ok = raw_send(Client, Request),
|
||||||
{'EXIT', _} -> error(closed);
|
_ = case catch raw_recv_head(Client) of
|
||||||
Data ->
|
{'EXIT', _} -> error(closed);
|
||||||
%% Cowboy always advertises itself as HTTP/1.1.
|
Data ->
|
||||||
{'HTTP/1.1', 200, _, Rest} = cow_http:parse_status_line(Data),
|
%% Cowboy always advertises itself as HTTP/1.1.
|
||||||
{Headers, <<>>} = cow_http:parse_headers(Rest),
|
{'HTTP/1.1', 200, _, Rest} = cow_http:parse_status_line(Data),
|
||||||
false = lists:keyfind(<<"content-length">>, 1, Headers),
|
{Headers, <<>>} = cow_http:parse_headers(Rest),
|
||||||
false = lists:keyfind(<<"transfer-encoding">>, 1, Headers)
|
false = lists:keyfind(<<"content-length">>, 1, Headers),
|
||||||
end,
|
false = lists:keyfind(<<"transfer-encoding">>, 1, Headers)
|
||||||
raw_expect_recv(Client, <<0:8000000>>),
|
end,
|
||||||
{error, closed} = raw_recv(Client, 1, 1000),
|
raw_expect_recv(Client, <<0:8000000>>),
|
||||||
ok.
|
{error, closed} = raw_recv(Client, 1, 1000)
|
||||||
|
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,18 +181,21 @@ set_options_chunked_false_ignored(Config) ->
|
||||||
chunked => true
|
chunked => true
|
||||||
}),
|
}),
|
||||||
Port = ranch:get_port(?FUNCTION_NAME),
|
Port = ranch:get_port(?FUNCTION_NAME),
|
||||||
ConnPid = gun_open([{type, tcp}, {protocol, http}, {port, Port}|Config]),
|
try
|
||||||
%% We do a first request setting the option but not
|
ConnPid = gun_open([{type, tcp}, {protocol, http}, {port, Port}|Config]),
|
||||||
%% using chunked transfer-encoding in the response.
|
%% We do a first request setting the option but not
|
||||||
StreamRef1 = gun:get(ConnPid, "/set_options/chunked_false_ignored"),
|
%% using chunked transfer-encoding in the response.
|
||||||
{response, nofin, 200, _} = gun:await(ConnPid, StreamRef1),
|
StreamRef1 = gun:get(ConnPid, "/set_options/chunked_false_ignored"),
|
||||||
{ok, <<"Hello world!">>} = gun:await_body(ConnPid, StreamRef1),
|
{response, nofin, 200, _} = gun:await(ConnPid, StreamRef1),
|
||||||
%% We then do a second request to confirm that chunked
|
{ok, <<"Hello world!">>} = gun:await_body(ConnPid, StreamRef1),
|
||||||
%% is not disabled for that second request.
|
%% We then do a second request to confirm that chunked
|
||||||
StreamRef2 = gun:get(ConnPid, "/resp/stream_reply2/200"),
|
%% is not disabled for that second request.
|
||||||
{response, nofin, 200, Headers} = gun:await(ConnPid, StreamRef2),
|
StreamRef2 = gun:get(ConnPid, "/resp/stream_reply2/200"),
|
||||||
{_, <<"chunked">>} = lists:keyfind(<<"transfer-encoding">>, 1, Headers),
|
{response, nofin, 200, Headers} = gun:await(ConnPid, StreamRef2),
|
||||||
ok.
|
{_, <<"chunked">>} = lists:keyfind(<<"transfer-encoding">>, 1, Headers)
|
||||||
|
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,17 +206,21 @@ set_options_idle_timeout(Config) ->
|
||||||
idle_timeout => 60000
|
idle_timeout => 60000
|
||||||
}),
|
}),
|
||||||
Port = ranch:get_port(?FUNCTION_NAME),
|
Port = ranch:get_port(?FUNCTION_NAME),
|
||||||
ConnPid = gun_open([{type, tcp}, {protocol, http}, {port, Port}|Config]),
|
try
|
||||||
_ = gun:post(ConnPid, "/set_options/idle_timeout_short",
|
ConnPid = gun_open([{type, tcp}, {protocol, http}, {port, Port}|Config]),
|
||||||
[{<<"content-type">>, <<"text/plain">>}]),
|
_ = gun:post(ConnPid, "/set_options/idle_timeout_short",
|
||||||
#{socket := Socket} = gun:info(ConnPid),
|
[{<<"content-type">>, <<"text/plain">>}]),
|
||||||
Pid = get_remote_pid_tcp(Socket),
|
#{socket := Socket} = gun:info(ConnPid),
|
||||||
Ref = erlang:monitor(process, Pid),
|
Pid = get_remote_pid_tcp(Socket),
|
||||||
receive
|
Ref = erlang:monitor(process, Pid),
|
||||||
{'DOWN', Ref, process, Pid, _} ->
|
receive
|
||||||
ok
|
{'DOWN', Ref, process, Pid, _} ->
|
||||||
after 2000 ->
|
ok
|
||||||
error(timeout)
|
after 2000 ->
|
||||||
|
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,30 +231,34 @@ 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),
|
||||||
ConnPid = gun_open([{type, tcp}, {protocol, http}, {port, Port}|Config]),
|
try
|
||||||
StreamRef = gun:post(ConnPid, "/set_options/idle_timeout_long",
|
ConnPid = gun_open([{type, tcp}, {protocol, http}, {port, Port}|Config]),
|
||||||
[{<<"content-type">>, <<"text/plain">>}]),
|
StreamRef = gun:post(ConnPid, "/set_options/idle_timeout_long",
|
||||||
#{socket := Socket} = gun:info(ConnPid),
|
[{<<"content-type">>, <<"text/plain">>}]),
|
||||||
Pid = get_remote_pid_tcp(Socket),
|
#{socket := Socket} = gun:info(ConnPid),
|
||||||
Ref = erlang:monitor(process, Pid),
|
Pid = get_remote_pid_tcp(Socket),
|
||||||
receive
|
Ref = erlang:monitor(process, Pid),
|
||||||
{'DOWN', Ref, process, Pid, Reason} ->
|
receive
|
||||||
error(Reason)
|
{'DOWN', Ref, process, Pid, Reason} ->
|
||||||
after 2000 ->
|
error(Reason)
|
||||||
ok
|
after 2000 ->
|
||||||
end,
|
|
||||||
%% Finish the first request and start a second one to confirm
|
|
||||||
%% the idle_timeout option is back to normal.
|
|
||||||
gun:data(ConnPid, StreamRef, fin, <<"Hello!">>),
|
|
||||||
{response, nofin, 200, _} = gun:await(ConnPid, StreamRef),
|
|
||||||
{ok, <<"Hello!">>} = gun:await_body(ConnPid, StreamRef),
|
|
||||||
_ = gun:post(ConnPid, "/echo/read_body",
|
|
||||||
[{<<"content-type">>, <<"text/plain">>}]),
|
|
||||||
receive
|
|
||||||
{'DOWN', Ref, process, Pid, _} ->
|
|
||||||
ok
|
ok
|
||||||
after 2000 ->
|
end,
|
||||||
error(timeout)
|
%% Finish the first request and start a second one to confirm
|
||||||
|
%% the idle_timeout option is back to normal.
|
||||||
|
gun:data(ConnPid, StreamRef, fin, <<"Hello!">>),
|
||||||
|
{response, nofin, 200, _} = gun:await(ConnPid, StreamRef),
|
||||||
|
{ok, <<"Hello!">>} = gun:await_body(ConnPid, StreamRef),
|
||||||
|
_ = gun:post(ConnPid, "/echo/read_body",
|
||||||
|
[{<<"content-type">>, <<"text/plain">>}]),
|
||||||
|
receive
|
||||||
|
{'DOWN', Ref, process, Pid, _} ->
|
||||||
|
ok
|
||||||
|
after 2000 ->
|
||||||
|
error(timeout)
|
||||||
|
end
|
||||||
|
after
|
||||||
|
cowboy:stop_listener(?FUNCTION_NAME)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
switch_protocol_flush(Config) ->
|
switch_protocol_flush(Config) ->
|
||||||
|
@ -240,12 +269,18 @@ 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),
|
||||||
Self = self(),
|
try
|
||||||
ConnPid = gun_open([{port, Port}, {type, tcp}, {protocol, http}|Config]),
|
Self = self(),
|
||||||
_ = gun:get(ConnPid, "/", [
|
ConnPid = gun_open([{port, Port}, {type, tcp}, {protocol, http}|Config]),
|
||||||
{<<"x-test-pid">>, pid_to_list(Self)}
|
_ = gun:get(ConnPid, "/", [
|
||||||
]),
|
{<<"x-test-pid">>, pid_to_list(Self)}
|
||||||
receive
|
]),
|
||||||
{Self, Events} ->
|
receive
|
||||||
switch_protocol_flush_h:validate(Events)
|
{Self, Events} ->
|
||||||
|
switch_protocol_flush_h:validate(Events)
|
||||||
|
after 5000 ->
|
||||||
|
error(timeout)
|
||||||
|
end
|
||||||
|
after
|
||||||
|
cowboy:stop_listener(?FUNCTION_NAME)
|
||||||
end.
|
end.
|
||||||
|
|
|
@ -82,25 +82,31 @@ set_env(Config0) ->
|
||||||
Config = cowboy_test:init_http(?FUNCTION_NAME, #{
|
Config = cowboy_test:init_http(?FUNCTION_NAME, #{
|
||||||
env => #{dispatch => []}
|
env => #{dispatch => []}
|
||||||
}, Config0),
|
}, Config0),
|
||||||
ConnPid1 = gun_open(Config),
|
try
|
||||||
Ref1 = gun:get(ConnPid1, "/"),
|
ConnPid1 = gun_open(Config),
|
||||||
{response, _, 400, _} = gun:await(ConnPid1, Ref1),
|
Ref1 = gun:get(ConnPid1, "/"),
|
||||||
cowboy:set_env(?FUNCTION_NAME, dispatch, init_dispatch(Config)),
|
{response, _, 400, _} = gun:await(ConnPid1, Ref1),
|
||||||
%% Only new connections get the updated environment.
|
cowboy:set_env(?FUNCTION_NAME, dispatch, init_dispatch(Config)),
|
||||||
ConnPid2 = gun_open(Config),
|
%% Only new connections get the updated environment.
|
||||||
Ref2 = gun:get(ConnPid2, "/"),
|
ConnPid2 = gun_open(Config),
|
||||||
{response, _, 200, _} = gun:await(ConnPid2, Ref2),
|
Ref2 = gun:get(ConnPid2, "/"),
|
||||||
ok.
|
{response, _, 200, _} = gun:await(ConnPid2, Ref2)
|
||||||
|
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),
|
||||||
ConnPid1 = gun_open(Config),
|
try
|
||||||
Ref1 = gun:get(ConnPid1, "/"),
|
ConnPid1 = gun_open(Config),
|
||||||
{response, _, 500, _} = gun:await(ConnPid1, Ref1),
|
Ref1 = gun:get(ConnPid1, "/"),
|
||||||
cowboy:set_env(?FUNCTION_NAME, dispatch, []),
|
{response, _, 500, _} = gun:await(ConnPid1, Ref1),
|
||||||
%% Only new connections get the updated environment.
|
cowboy:set_env(?FUNCTION_NAME, dispatch, []),
|
||||||
ConnPid2 = gun_open(Config),
|
%% Only new connections get the updated environment.
|
||||||
Ref2 = gun:get(ConnPid2, "/"),
|
ConnPid2 = gun_open(Config),
|
||||||
{response, _, 400, _} = gun:await(ConnPid2, Ref2),
|
Ref2 = gun:get(ConnPid2, "/"),
|
||||||
ok.
|
{response, _, 400, _} = gun:await(ConnPid2, Ref2)
|
||||||
|
after
|
||||||
|
cowboy:stop_listener(?FUNCTION_NAME)
|
||||||
|
end.
|
||||||
|
|
|
@ -1593,15 +1593,18 @@ 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),
|
||||||
#{code := 200, body := <<>>} = do_raw(Config, [
|
try
|
||||||
"GET /echo/host HTTP/1.1\r\n"
|
#{code := 200, body := <<>>} = do_raw(Config, [
|
||||||
"Host:\r\n"
|
"GET /echo/host HTTP/1.1\r\n"
|
||||||
"\r\n"]),
|
"Host:\r\n"
|
||||||
#{code := 200, body := <<>>} = do_raw(Config, [
|
"\r\n"]),
|
||||||
"GET /echo/host HTTP/1.1\r\n"
|
#{code := 200, body := <<>>} = do_raw(Config, [
|
||||||
"Host: \r\n"
|
"GET /echo/host HTTP/1.1\r\n"
|
||||||
"\r\n"]),
|
"Host: \r\n"
|
||||||
cowboy:stop_listener(?FUNCTION_NAME).
|
"\r\n"])
|
||||||
|
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,27 +1327,30 @@ 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),
|
||||||
%% Do the handshake.
|
try
|
||||||
{ok, Socket} = do_handshake(Config),
|
%% Do the handshake.
|
||||||
%% Send a HEADERS frame initiating a stream followed by
|
{ok, Socket} = do_handshake(Config),
|
||||||
%% a single 30000 bytes DATA frame.
|
%% Send a HEADERS frame initiating a stream followed by
|
||||||
Headers = [
|
%% a single 30000 bytes DATA frame.
|
||||||
{<<":method">>, <<"POST">>},
|
Headers = [
|
||||||
{<<":scheme">>, <<"http">>},
|
{<<":method">>, <<"POST">>},
|
||||||
{<<":authority">>, <<"localhost">>}, %% @todo Correct port number.
|
{<<":scheme">>, <<"http">>},
|
||||||
{<<":path">>, <<"/long_polling">>}
|
{<<":authority">>, <<"localhost">>}, %% @todo Correct port number.
|
||||||
],
|
{<<":path">>, <<"/long_polling">>}
|
||||||
{HeadersBlock, _} = cow_hpack:encode(Headers),
|
],
|
||||||
ok = gen_tcp:send(Socket, [
|
{HeadersBlock, _} = cow_hpack:encode(Headers),
|
||||||
cow_http2:headers(1, nofin, HeadersBlock),
|
ok = gen_tcp:send(Socket, [
|
||||||
cow_http2:data(1, fin, <<0:30000/unit:8>>)
|
cow_http2:headers(1, nofin, HeadersBlock),
|
||||||
]),
|
cow_http2:data(1, fin, <<0:30000/unit:8>>)
|
||||||
%% Receive a proper response.
|
]),
|
||||||
{ok, << Len2:24, 1:8, _:40 >>} = gen_tcp:recv(Socket, 9, 6000),
|
%% Receive a proper response.
|
||||||
{ok, _} = gen_tcp:recv(Socket, Len2, 6000),
|
{ok, << Len2:24, 1:8, _:40 >>} = gen_tcp:recv(Socket, 9, 6000),
|
||||||
%% No errors follow due to our sending of a 25000 bytes frame.
|
{ok, _} = gen_tcp:recv(Socket, Len2, 6000),
|
||||||
{error, timeout} = gen_tcp:recv(Socket, 0, 1000),
|
%% No errors follow due to our sending of a 25000 bytes frame.
|
||||||
cowboy:stop_listener(?FUNCTION_NAME).
|
{error, timeout} = gen_tcp:recv(Socket, 0, 1000)
|
||||||
|
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,24 +1360,27 @@ 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),
|
||||||
%% Do the handshake.
|
try
|
||||||
{ok, Socket} = do_handshake(Config),
|
%% Do the handshake.
|
||||||
%% Send a HEADERS frame initiating a stream followed by
|
{ok, Socket} = do_handshake(Config),
|
||||||
%% a single DATA frame larger than 30000 bytes.
|
%% Send a HEADERS frame initiating a stream followed by
|
||||||
Headers = [
|
%% a single DATA frame larger than 30000 bytes.
|
||||||
{<<":method">>, <<"POST">>},
|
Headers = [
|
||||||
{<<":scheme">>, <<"http">>},
|
{<<":method">>, <<"POST">>},
|
||||||
{<<":authority">>, <<"localhost">>}, %% @todo Correct port number.
|
{<<":scheme">>, <<"http">>},
|
||||||
{<<":path">>, <<"/long_polling">>}
|
{<<":authority">>, <<"localhost">>}, %% @todo Correct port number.
|
||||||
],
|
{<<":path">>, <<"/long_polling">>}
|
||||||
{HeadersBlock, _} = cow_hpack:encode(Headers),
|
],
|
||||||
ok = gen_tcp:send(Socket, [
|
{HeadersBlock, _} = cow_hpack:encode(Headers),
|
||||||
cow_http2:headers(1, nofin, HeadersBlock),
|
ok = gen_tcp:send(Socket, [
|
||||||
cow_http2:data(1, fin, <<0:30001/unit:8>>)
|
cow_http2:headers(1, nofin, HeadersBlock),
|
||||||
]),
|
cow_http2:data(1, fin, <<0:30001/unit:8>>)
|
||||||
%% Receive a FRAME_SIZE_ERROR connection error.
|
]),
|
||||||
{ok, << _:24, 7:8, _:72, 6:32 >>} = gen_tcp:recv(Socket, 17, 6000),
|
%% Receive a FRAME_SIZE_ERROR connection error.
|
||||||
cowboy:stop_listener(?FUNCTION_NAME).
|
{ok, << _:24, 7:8, _:72, 6:32 >>} = gen_tcp:recv(Socket, 17, 6000)
|
||||||
|
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,40 +2561,43 @@ 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),
|
||||||
%% Do the handhsake.
|
try
|
||||||
{ok, Socket} = gen_tcp:connect("localhost", config(port, Config), [binary, {active, false}]),
|
%% Do the handhsake.
|
||||||
%% Send a valid preface.
|
{ok, Socket} = gen_tcp:connect("localhost", config(port, Config), [binary, {active, false}]),
|
||||||
ok = gen_tcp:send(Socket, ["PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n",
|
%% Send a valid preface.
|
||||||
cow_http2:settings(#{header_table_size => HeaderTableSize})]),
|
ok = gen_tcp:send(Socket, ["PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n",
|
||||||
%% Receive the server preface.
|
cow_http2:settings(#{header_table_size => HeaderTableSize})]),
|
||||||
{ok, << Len0:24 >>} = gen_tcp:recv(Socket, 3, 1000),
|
%% Receive the server preface.
|
||||||
{ok, Data = <<_:48, _:Len0/binary>>} = gen_tcp:recv(Socket, 6 + Len0, 1000),
|
{ok, << Len0:24 >>} = gen_tcp:recv(Socket, 3, 1000),
|
||||||
%% Confirm the server's SETTINGS_HEADERS_TABLE_SIZE uses HeaderTableSize.
|
{ok, Data = <<_:48, _:Len0/binary>>} = gen_tcp:recv(Socket, 6 + Len0, 1000),
|
||||||
{ok, {settings, #{header_table_size := HeaderTableSize}}, <<>>}
|
%% Confirm the server's SETTINGS_HEADERS_TABLE_SIZE uses HeaderTableSize.
|
||||||
= cow_http2:parse(<<Len0:24, Data/binary>>),
|
{ok, {settings, #{header_table_size := HeaderTableSize}}, <<>>}
|
||||||
%% Send the SETTINGS ack.
|
= cow_http2:parse(<<Len0:24, Data/binary>>),
|
||||||
ok = gen_tcp:send(Socket, cow_http2:settings_ack()),
|
%% Send the SETTINGS ack.
|
||||||
%% Receive the SETTINGS ack.
|
ok = gen_tcp:send(Socket, cow_http2:settings_ack()),
|
||||||
{ok, << 0:24, 4:8, 1:8, 0:32 >>} = gen_tcp:recv(Socket, 9, 1000),
|
%% Receive the SETTINGS ack.
|
||||||
%% Initialize decoding/encoding states.
|
{ok, << 0:24, 4:8, 1:8, 0:32 >>} = gen_tcp:recv(Socket, 9, 1000),
|
||||||
DecodeState = cow_hpack:init(),
|
%% Initialize decoding/encoding states.
|
||||||
EncodeState = cow_hpack:set_max_size(HeaderTableSize, cow_hpack:init()),
|
DecodeState = cow_hpack:init(),
|
||||||
%% Send a HEADERS frame as a request.
|
EncodeState = cow_hpack:set_max_size(HeaderTableSize, cow_hpack:init()),
|
||||||
{ReqHeadersBlock1, _} = cow_hpack:encode([
|
%% Send a HEADERS frame as a request.
|
||||||
{<<":method">>, <<"GET">>},
|
{ReqHeadersBlock1, _} = cow_hpack:encode([
|
||||||
{<<":scheme">>, <<"http">>},
|
{<<":method">>, <<"GET">>},
|
||||||
{<<":authority">>, <<"localhost">>}, %% @todo Correct port number.
|
{<<":scheme">>, <<"http">>},
|
||||||
{<<":path">>, <<"/">>}
|
{<<":authority">>, <<"localhost">>}, %% @todo Correct port number.
|
||||||
], EncodeState),
|
{<<":path">>, <<"/">>}
|
||||||
ok = gen_tcp:send(Socket, cow_http2:headers(1, fin, ReqHeadersBlock1)),
|
], EncodeState),
|
||||||
%% Receive a HEADERS frame as a response.
|
ok = gen_tcp:send(Socket, cow_http2:headers(1, fin, ReqHeadersBlock1)),
|
||||||
{ok, << Len1:24, 1:8, _:40 >>} = gen_tcp:recv(Socket, 9, 6000),
|
%% Receive a HEADERS frame as a response.
|
||||||
{ok, RespHeadersBlock1} = gen_tcp:recv(Socket, Len1, 6000),
|
{ok, << Len1:24, 1:8, _:40 >>} = gen_tcp:recv(Socket, 9, 6000),
|
||||||
{RespHeaders, _} = cow_hpack:decode(RespHeadersBlock1, DecodeState),
|
{ok, RespHeadersBlock1} = gen_tcp:recv(Socket, Len1, 6000),
|
||||||
{_, <<"200">>} = lists:keyfind(<<":status">>, 1, RespHeaders),
|
{RespHeaders, _} = cow_hpack:decode(RespHeadersBlock1, DecodeState),
|
||||||
%% The decoding succeeded on the server, confirming that
|
{_, <<"200">>} = lists:keyfind(<<":status">>, 1, RespHeaders)
|
||||||
%% the table size was updated to HeaderTableSize.
|
%% The decoding succeeded on the server, confirming that
|
||||||
cowboy:stop_listener(?FUNCTION_NAME).
|
%% the table size was updated to HeaderTableSize.
|
||||||
|
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,23 +2607,26 @@ 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),
|
||||||
{ok, Socket} = do_handshake(Config),
|
try
|
||||||
%% Send two HEADERS frames as two separate streams.
|
{ok, Socket} = do_handshake(Config),
|
||||||
Headers = [
|
%% Send two HEADERS frames as two separate streams.
|
||||||
{<<":method">>, <<"GET">>},
|
Headers = [
|
||||||
{<<":scheme">>, <<"http">>},
|
{<<":method">>, <<"GET">>},
|
||||||
{<<":authority">>, <<"localhost">>}, %% @todo Correct port number.
|
{<<":scheme">>, <<"http">>},
|
||||||
{<<":path">>, <<"/long_polling">>}
|
{<<":authority">>, <<"localhost">>}, %% @todo Correct port number.
|
||||||
],
|
{<<":path">>, <<"/long_polling">>}
|
||||||
{ReqHeadersBlock1, EncodeState} = cow_hpack:encode(Headers),
|
],
|
||||||
{ReqHeadersBlock2, _} = cow_hpack:encode(Headers, EncodeState),
|
{ReqHeadersBlock1, EncodeState} = cow_hpack:encode(Headers),
|
||||||
ok = gen_tcp:send(Socket, [
|
{ReqHeadersBlock2, _} = cow_hpack:encode(Headers, EncodeState),
|
||||||
cow_http2:headers(1, fin, ReqHeadersBlock1),
|
ok = gen_tcp:send(Socket, [
|
||||||
cow_http2:headers(3, fin, ReqHeadersBlock2)
|
cow_http2:headers(1, fin, ReqHeadersBlock1),
|
||||||
]),
|
cow_http2:headers(3, fin, ReqHeadersBlock2)
|
||||||
%% Receive a REFUSED_STREAM stream error.
|
]),
|
||||||
{ok, << _:24, 3:8, _:8, 3:32, 7:32 >>} = gen_tcp:recv(Socket, 13, 6000),
|
%% Receive a REFUSED_STREAM stream error.
|
||||||
cowboy:stop_listener(?FUNCTION_NAME).
|
{ok, << _:24, 3:8, _:8, 3:32, 7:32 >>} = gen_tcp:recv(Socket, 13, 6000)
|
||||||
|
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,18 +2636,21 @@ 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),
|
||||||
{ok, Socket} = do_handshake(Config),
|
try
|
||||||
%% Send a HEADERS frame.
|
{ok, Socket} = do_handshake(Config),
|
||||||
{HeadersBlock, _} = cow_hpack:encode([
|
%% Send a HEADERS frame.
|
||||||
{<<":method">>, <<"GET">>},
|
{HeadersBlock, _} = cow_hpack:encode([
|
||||||
{<<":scheme">>, <<"http">>},
|
{<<":method">>, <<"GET">>},
|
||||||
{<<":authority">>, <<"localhost">>}, %% @todo Correct port number.
|
{<<":scheme">>, <<"http">>},
|
||||||
{<<":path">>, <<"/long_polling">>}
|
{<<":authority">>, <<"localhost">>}, %% @todo Correct port number.
|
||||||
]),
|
{<<":path">>, <<"/long_polling">>}
|
||||||
ok = gen_tcp:send(Socket, cow_http2:headers(1, fin, HeadersBlock)),
|
]),
|
||||||
%% Receive a REFUSED_STREAM stream error.
|
ok = gen_tcp:send(Socket, cow_http2:headers(1, fin, HeadersBlock)),
|
||||||
{ok, << _:24, 3:8, _:8, 1:32, 7:32 >>} = gen_tcp:recv(Socket, 13, 6000),
|
%% Receive a REFUSED_STREAM stream error.
|
||||||
cowboy:stop_listener(?FUNCTION_NAME).
|
{ok, << _:24, 3:8, _:8, 1:32, 7:32 >>} = gen_tcp:recv(Socket, 13, 6000)
|
||||||
|
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,44 +2678,47 @@ 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),
|
||||||
%% We need to do the handshake manually because a WINDOW_UPDATE
|
try
|
||||||
%% frame will be sent to update the connection window.
|
%% We need to do the handshake manually because a WINDOW_UPDATE
|
||||||
{ok, Socket} = gen_tcp:connect("localhost", config(port, Config), [binary, {active, false}]),
|
%% frame will be sent to update the connection window.
|
||||||
%% Send a valid preface.
|
{ok, Socket} = gen_tcp:connect("localhost", config(port, Config), [binary, {active, false}]),
|
||||||
ok = gen_tcp:send(Socket, ["PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n", cow_http2:settings(#{})]),
|
%% Send a valid preface.
|
||||||
%% Receive the server preface.
|
ok = gen_tcp:send(Socket, ["PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n", cow_http2:settings(#{})]),
|
||||||
{ok, << Len1:24 >>} = gen_tcp:recv(Socket, 3, 1000),
|
%% Receive the server preface.
|
||||||
{ok, << 4:8, 0:40, _:Len1/binary >>} = gen_tcp:recv(Socket, 6 + Len1, 1000),
|
{ok, << Len1:24 >>} = gen_tcp:recv(Socket, 3, 1000),
|
||||||
%% Send the SETTINGS ack.
|
{ok, << 4:8, 0:40, _:Len1/binary >>} = gen_tcp:recv(Socket, 6 + Len1, 1000),
|
||||||
ok = gen_tcp:send(Socket, cow_http2:settings_ack()),
|
%% Send the SETTINGS ack.
|
||||||
%% Receive the WINDOW_UPDATE for the connection.
|
ok = gen_tcp:send(Socket, cow_http2:settings_ack()),
|
||||||
{ok, << 4:24, 8:8, 0:40, _:32 >>} = gen_tcp:recv(Socket, 13, 1000),
|
%% Receive the WINDOW_UPDATE for the connection.
|
||||||
%% Receive the SETTINGS ack.
|
{ok, << 4:24, 8:8, 0:40, _:32 >>} = gen_tcp:recv(Socket, 13, 1000),
|
||||||
{ok, << 0:24, 4:8, 1:8, 0:32 >>} = gen_tcp:recv(Socket, 9, 1000),
|
%% Receive the SETTINGS ack.
|
||||||
%% Send a HEADERS frame initiating a stream followed by
|
{ok, << 0:24, 4:8, 1:8, 0:32 >>} = gen_tcp:recv(Socket, 9, 1000),
|
||||||
%% DATA frames totaling 90000 bytes of body.
|
%% Send a HEADERS frame initiating a stream followed by
|
||||||
Headers = [
|
%% DATA frames totaling 90000 bytes of body.
|
||||||
{<<":method">>, <<"POST">>},
|
Headers = [
|
||||||
{<<":scheme">>, <<"http">>},
|
{<<":method">>, <<"POST">>},
|
||||||
{<<":authority">>, <<"localhost">>}, %% @todo Correct port number.
|
{<<":scheme">>, <<"http">>},
|
||||||
{<<":path">>, <<"/long_polling">>}
|
{<<":authority">>, <<"localhost">>}, %% @todo Correct port number.
|
||||||
],
|
{<<":path">>, <<"/long_polling">>}
|
||||||
{HeadersBlock, _} = cow_hpack:encode(Headers),
|
],
|
||||||
ok = gen_tcp:send(Socket, [
|
{HeadersBlock, _} = cow_hpack:encode(Headers),
|
||||||
cow_http2:headers(1, nofin, HeadersBlock),
|
ok = gen_tcp:send(Socket, [
|
||||||
cow_http2:data(1, nofin, <<0:15000/unit:8>>),
|
cow_http2:headers(1, nofin, HeadersBlock),
|
||||||
cow_http2:data(1, nofin, <<0:15000/unit:8>>),
|
cow_http2:data(1, nofin, <<0:15000/unit:8>>),
|
||||||
cow_http2:data(1, nofin, <<0:15000/unit:8>>),
|
cow_http2:data(1, nofin, <<0:15000/unit:8>>),
|
||||||
cow_http2:data(1, nofin, <<0:15000/unit:8>>),
|
cow_http2:data(1, nofin, <<0:15000/unit:8>>),
|
||||||
cow_http2:data(1, nofin, <<0:15000/unit:8>>),
|
cow_http2:data(1, nofin, <<0:15000/unit:8>>),
|
||||||
cow_http2:data(1, fin, <<0:15000/unit:8>>)
|
cow_http2:data(1, nofin, <<0:15000/unit:8>>),
|
||||||
]),
|
cow_http2:data(1, fin, <<0:15000/unit:8>>)
|
||||||
%% Receive a proper response.
|
]),
|
||||||
{ok, << Len2:24, 1:8, _:40 >>} = gen_tcp:recv(Socket, 9, 6000),
|
%% Receive a proper response.
|
||||||
{ok, _} = gen_tcp:recv(Socket, Len2, 6000),
|
{ok, << Len2:24, 1:8, _:40 >>} = gen_tcp:recv(Socket, 9, 6000),
|
||||||
%% No errors follow due to our sending of more than 65535 bytes of data.
|
{ok, _} = gen_tcp:recv(Socket, Len2, 6000),
|
||||||
{error, timeout} = gen_tcp:recv(Socket, 0, 1000),
|
%% No errors follow due to our sending of more than 65535 bytes of data.
|
||||||
cowboy:stop_listener(?FUNCTION_NAME).
|
{error, timeout} = gen_tcp:recv(Socket, 0, 1000)
|
||||||
|
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,36 +2729,39 @@ 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),
|
||||||
%% We need to do the handshake manually because we don't
|
try
|
||||||
%% want to send the SETTINGS ack immediately.
|
%% We need to do the handshake manually because we don't
|
||||||
{ok, Socket} = gen_tcp:connect("localhost", config(port, Config), [binary, {active, false}]),
|
%% want to send the SETTINGS ack immediately.
|
||||||
%% Send a valid preface.
|
{ok, Socket} = gen_tcp:connect("localhost", config(port, Config), [binary, {active, false}]),
|
||||||
ok = gen_tcp:send(Socket, ["PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n", cow_http2:settings(#{})]),
|
%% Send a valid preface.
|
||||||
%% Receive the server preface.
|
ok = gen_tcp:send(Socket, ["PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n", cow_http2:settings(#{})]),
|
||||||
{ok, << Len1:24 >>} = gen_tcp:recv(Socket, 3, 1000),
|
%% Receive the server preface.
|
||||||
{ok, << 4:8, 0:40, _:Len1/binary >>} = gen_tcp:recv(Socket, 6 + Len1, 1000),
|
{ok, << Len1:24 >>} = gen_tcp:recv(Socket, 3, 1000),
|
||||||
%%
|
{ok, << 4:8, 0:40, _:Len1/binary >>} = gen_tcp:recv(Socket, 6 + Len1, 1000),
|
||||||
%% Don't send the SETTINGS ack yet! We want to create a stream first.
|
%%
|
||||||
%%
|
%% Don't send the SETTINGS ack yet! We want to create a stream first.
|
||||||
%% Receive the SETTINGS ack.
|
%%
|
||||||
{ok, << 0:24, 4:8, 1:8, 0:32 >>} = gen_tcp:recv(Socket, 9, 1000),
|
%% Receive the SETTINGS ack.
|
||||||
%% Send a HEADERS frame initiating a stream, a SETTINGS ack
|
{ok, << 0:24, 4:8, 1:8, 0:32 >>} = gen_tcp:recv(Socket, 9, 1000),
|
||||||
%% and a small DATA frame despite no window available in the stream.
|
%% Send a HEADERS frame initiating a stream, a SETTINGS ack
|
||||||
Headers = [
|
%% and a small DATA frame despite no window available in the stream.
|
||||||
{<<":method">>, <<"POST">>},
|
Headers = [
|
||||||
{<<":scheme">>, <<"http">>},
|
{<<":method">>, <<"POST">>},
|
||||||
{<<":authority">>, <<"localhost">>}, %% @todo Correct port number.
|
{<<":scheme">>, <<"http">>},
|
||||||
{<<":path">>, <<"/long_polling">>}
|
{<<":authority">>, <<"localhost">>}, %% @todo Correct port number.
|
||||||
],
|
{<<":path">>, <<"/long_polling">>}
|
||||||
{HeadersBlock, _} = cow_hpack:encode(Headers),
|
],
|
||||||
ok = gen_tcp:send(Socket, [
|
{HeadersBlock, _} = cow_hpack:encode(Headers),
|
||||||
cow_http2:headers(1, nofin, HeadersBlock),
|
ok = gen_tcp:send(Socket, [
|
||||||
cow_http2:settings_ack(),
|
cow_http2:headers(1, nofin, HeadersBlock),
|
||||||
cow_http2:data(1, fin, <<0:32/unit:8>>)
|
cow_http2:settings_ack(),
|
||||||
]),
|
cow_http2:data(1, fin, <<0:32/unit:8>>)
|
||||||
%% Receive a FLOW_CONTROL_ERROR stream error.
|
]),
|
||||||
{ok, << _:24, 3:8, _:8, 1:32, 3:32 >>} = gen_tcp:recv(Socket, 13, 6000),
|
%% Receive a FLOW_CONTROL_ERROR stream error.
|
||||||
cowboy:stop_listener(?FUNCTION_NAME).
|
{ok, << _:24, 3:8, _:8, 1:32, 3:32 >>} = gen_tcp:recv(Socket, 13, 6000)
|
||||||
|
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,41 +2772,44 @@ 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),
|
||||||
%% We need to do the handshake manually because we don't
|
try
|
||||||
%% want to send the SETTINGS ack.
|
%% We need to do the handshake manually because we don't
|
||||||
{ok, Socket} = gen_tcp:connect("localhost", config(port, Config), [binary, {active, false}]),
|
%% want to send the SETTINGS ack.
|
||||||
%% Send a valid preface.
|
{ok, Socket} = gen_tcp:connect("localhost", config(port, Config), [binary, {active, false}]),
|
||||||
ok = gen_tcp:send(Socket, ["PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n", cow_http2:settings(#{})]),
|
%% Send a valid preface.
|
||||||
%% Receive the server preface.
|
ok = gen_tcp:send(Socket, ["PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n", cow_http2:settings(#{})]),
|
||||||
{ok, << Len1:24 >>} = gen_tcp:recv(Socket, 3, 1000),
|
%% Receive the server preface.
|
||||||
{ok, << 4:8, 0:40, _:Len1/binary >>} = gen_tcp:recv(Socket, 6 + Len1, 1000),
|
{ok, << Len1:24 >>} = gen_tcp:recv(Socket, 3, 1000),
|
||||||
%%
|
{ok, << 4:8, 0:40, _:Len1/binary >>} = gen_tcp:recv(Socket, 6 + Len1, 1000),
|
||||||
%% Don't send the SETTINGS ack! We want the server to keep the original settings.
|
%%
|
||||||
%%
|
%% Don't send the SETTINGS ack! We want the server to keep the original settings.
|
||||||
%% Receive the SETTINGS ack.
|
%%
|
||||||
{ok, << 0:24, 4:8, 1:8, 0:32 >>} = gen_tcp:recv(Socket, 9, 1000),
|
%% Receive the SETTINGS ack.
|
||||||
%% Send a HEADERS frame initiating a stream followed by
|
{ok, << 0:24, 4:8, 1:8, 0:32 >>} = gen_tcp:recv(Socket, 9, 1000),
|
||||||
%% DATA frames totaling 60000 bytes of body.
|
%% Send a HEADERS frame initiating a stream followed by
|
||||||
Headers = [
|
%% DATA frames totaling 60000 bytes of body.
|
||||||
{<<":method">>, <<"POST">>},
|
Headers = [
|
||||||
{<<":scheme">>, <<"http">>},
|
{<<":method">>, <<"POST">>},
|
||||||
{<<":authority">>, <<"localhost">>}, %% @todo Correct port number.
|
{<<":scheme">>, <<"http">>},
|
||||||
{<<":path">>, <<"/long_polling">>}
|
{<<":authority">>, <<"localhost">>}, %% @todo Correct port number.
|
||||||
],
|
{<<":path">>, <<"/long_polling">>}
|
||||||
{HeadersBlock, _} = cow_hpack:encode(Headers),
|
],
|
||||||
ok = gen_tcp:send(Socket, [
|
{HeadersBlock, _} = cow_hpack:encode(Headers),
|
||||||
cow_http2:headers(1, nofin, HeadersBlock),
|
ok = gen_tcp:send(Socket, [
|
||||||
cow_http2:data(1, nofin, <<0:15000/unit:8>>),
|
cow_http2:headers(1, nofin, HeadersBlock),
|
||||||
cow_http2:data(1, nofin, <<0:15000/unit:8>>),
|
cow_http2:data(1, nofin, <<0:15000/unit:8>>),
|
||||||
cow_http2:data(1, nofin, <<0:15000/unit:8>>),
|
cow_http2:data(1, nofin, <<0:15000/unit:8>>),
|
||||||
cow_http2:data(1, fin, <<0:15000/unit:8>>)
|
cow_http2:data(1, nofin, <<0:15000/unit:8>>),
|
||||||
]),
|
cow_http2:data(1, fin, <<0:15000/unit:8>>)
|
||||||
%% Receive a proper response.
|
]),
|
||||||
{ok, << Len2:24, 1:8, _:40 >>} = gen_tcp:recv(Socket, 9, 6000),
|
%% Receive a proper response.
|
||||||
{ok, _} = gen_tcp:recv(Socket, Len2, 6000),
|
{ok, << Len2:24, 1:8, _:40 >>} = gen_tcp:recv(Socket, 9, 6000),
|
||||||
%% No errors follow due to our sending of more than 0 bytes of data.
|
{ok, _} = gen_tcp:recv(Socket, Len2, 6000),
|
||||||
{error, timeout} = gen_tcp:recv(Socket, 0, 1000),
|
%% No errors follow due to our sending of more than 0 bytes of data.
|
||||||
cowboy:stop_listener(?FUNCTION_NAME).
|
{error, timeout} = gen_tcp:recv(Socket, 0, 1000)
|
||||||
|
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,27 +2819,30 @@ 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),
|
||||||
%% Do the handshake.
|
try
|
||||||
{ok, Socket} = do_handshake(Config),
|
%% Do the handshake.
|
||||||
%% Send a HEADERS frame initiating a stream followed by
|
{ok, Socket} = do_handshake(Config),
|
||||||
%% a single 25000 bytes DATA frame.
|
%% Send a HEADERS frame initiating a stream followed by
|
||||||
Headers = [
|
%% a single 25000 bytes DATA frame.
|
||||||
{<<":method">>, <<"POST">>},
|
Headers = [
|
||||||
{<<":scheme">>, <<"http">>},
|
{<<":method">>, <<"POST">>},
|
||||||
{<<":authority">>, <<"localhost">>}, %% @todo Correct port number.
|
{<<":scheme">>, <<"http">>},
|
||||||
{<<":path">>, <<"/long_polling">>}
|
{<<":authority">>, <<"localhost">>}, %% @todo Correct port number.
|
||||||
],
|
{<<":path">>, <<"/long_polling">>}
|
||||||
{HeadersBlock, _} = cow_hpack:encode(Headers),
|
],
|
||||||
ok = gen_tcp:send(Socket, [
|
{HeadersBlock, _} = cow_hpack:encode(Headers),
|
||||||
cow_http2:headers(1, nofin, HeadersBlock),
|
ok = gen_tcp:send(Socket, [
|
||||||
cow_http2:data(1, fin, <<0:25000/unit:8>>)
|
cow_http2:headers(1, nofin, HeadersBlock),
|
||||||
]),
|
cow_http2:data(1, fin, <<0:25000/unit:8>>)
|
||||||
%% Receive a proper response.
|
]),
|
||||||
{ok, << Len2:24, 1:8, _:40 >>} = gen_tcp:recv(Socket, 9, 6000),
|
%% Receive a proper response.
|
||||||
{ok, _} = gen_tcp:recv(Socket, Len2, 6000),
|
{ok, << Len2:24, 1:8, _:40 >>} = gen_tcp:recv(Socket, 9, 6000),
|
||||||
%% No errors follow due to our sending of a 25000 bytes frame.
|
{ok, _} = gen_tcp:recv(Socket, Len2, 6000),
|
||||||
{error, timeout} = gen_tcp:recv(Socket, 0, 1000),
|
%% No errors follow due to our sending of a 25000 bytes frame.
|
||||||
cowboy:stop_listener(?FUNCTION_NAME).
|
{error, timeout} = gen_tcp:recv(Socket, 0, 1000)
|
||||||
|
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,28 +3042,31 @@ 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),
|
||||||
{ok, Socket} = do_handshake(Config),
|
try
|
||||||
%% Send a HEADERS frame initiating a stream followed by
|
{ok, Socket} = do_handshake(Config),
|
||||||
%% DATA frames totaling 90000 bytes of body.
|
%% Send a HEADERS frame initiating a stream followed by
|
||||||
Headers = [
|
%% DATA frames totaling 90000 bytes of body.
|
||||||
{<<":method">>, <<"POST">>},
|
Headers = [
|
||||||
{<<":scheme">>, <<"http">>},
|
{<<":method">>, <<"POST">>},
|
||||||
{<<":authority">>, <<"localhost">>}, %% @todo Correct port number.
|
{<<":scheme">>, <<"http">>},
|
||||||
{<<":path">>, <<"/long_polling">>}
|
{<<":authority">>, <<"localhost">>}, %% @todo Correct port number.
|
||||||
],
|
{<<":path">>, <<"/long_polling">>}
|
||||||
{HeadersBlock, _} = cow_hpack:encode(Headers),
|
],
|
||||||
ok = gen_tcp:send(Socket, [
|
{HeadersBlock, _} = cow_hpack:encode(Headers),
|
||||||
cow_http2:headers(1, nofin, HeadersBlock),
|
ok = gen_tcp:send(Socket, [
|
||||||
cow_http2:data(1, nofin, <<0:15000/unit:8>>),
|
cow_http2:headers(1, nofin, HeadersBlock),
|
||||||
cow_http2:data(1, nofin, <<0:15000/unit:8>>),
|
cow_http2:data(1, nofin, <<0:15000/unit:8>>),
|
||||||
cow_http2:data(1, nofin, <<0:15000/unit:8>>),
|
cow_http2:data(1, nofin, <<0:15000/unit:8>>),
|
||||||
cow_http2:data(1, nofin, <<0:15000/unit:8>>),
|
cow_http2:data(1, nofin, <<0:15000/unit:8>>),
|
||||||
cow_http2:data(1, nofin, <<0:15000/unit:8>>),
|
cow_http2:data(1, nofin, <<0:15000/unit:8>>),
|
||||||
cow_http2:data(1, fin, <<0:15000/unit:8>>)
|
cow_http2:data(1, nofin, <<0:15000/unit:8>>),
|
||||||
]),
|
cow_http2:data(1, fin, <<0:15000/unit:8>>)
|
||||||
%% Receive a FLOW_CONTROL_ERROR connection error.
|
]),
|
||||||
{ok, << _:24, 7:8, _:72, 3:32 >>} = gen_tcp:recv(Socket, 17, 6000),
|
%% Receive a FLOW_CONTROL_ERROR connection error.
|
||||||
cowboy:stop_listener(?FUNCTION_NAME).
|
{ok, << _:24, 7:8, _:72, 3:32 >>} = gen_tcp:recv(Socket, 17, 6000)
|
||||||
|
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,41 +3077,44 @@ 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),
|
||||||
%% We need to do the handshake manually because a WINDOW_UPDATE
|
try
|
||||||
%% frame will be sent to update the connection window.
|
%% We need to do the handshake manually because a WINDOW_UPDATE
|
||||||
{ok, Socket} = gen_tcp:connect("localhost", config(port, Config), [binary, {active, false}]),
|
%% frame will be sent to update the connection window.
|
||||||
%% Send a valid preface.
|
{ok, Socket} = gen_tcp:connect("localhost", config(port, Config), [binary, {active, false}]),
|
||||||
ok = gen_tcp:send(Socket, ["PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n", cow_http2:settings(#{})]),
|
%% Send a valid preface.
|
||||||
%% Receive the server preface.
|
ok = gen_tcp:send(Socket, ["PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n", cow_http2:settings(#{})]),
|
||||||
{ok, << Len1:24 >>} = gen_tcp:recv(Socket, 3, 1000),
|
%% Receive the server preface.
|
||||||
{ok, << 4:8, 0:40, _:Len1/binary >>} = gen_tcp:recv(Socket, 6 + Len1, 1000),
|
{ok, << Len1:24 >>} = gen_tcp:recv(Socket, 3, 1000),
|
||||||
%% Send the SETTINGS ack.
|
{ok, << 4:8, 0:40, _:Len1/binary >>} = gen_tcp:recv(Socket, 6 + Len1, 1000),
|
||||||
ok = gen_tcp:send(Socket, cow_http2:settings_ack()),
|
%% Send the SETTINGS ack.
|
||||||
%% Receive the WINDOW_UPDATE for the connection.
|
ok = gen_tcp:send(Socket, cow_http2:settings_ack()),
|
||||||
{ok, << 4:24, 8:8, 0:40, _:32 >>} = gen_tcp:recv(Socket, 13, 1000),
|
%% Receive the WINDOW_UPDATE for the connection.
|
||||||
%% Receive the SETTINGS ack.
|
{ok, << 4:24, 8:8, 0:40, _:32 >>} = gen_tcp:recv(Socket, 13, 1000),
|
||||||
{ok, << 0:24, 4:8, 1:8, 0:32 >>} = gen_tcp:recv(Socket, 9, 1000),
|
%% Receive the SETTINGS ack.
|
||||||
%% Send a HEADERS frame initiating a stream followed by
|
{ok, << 0:24, 4:8, 1:8, 0:32 >>} = gen_tcp:recv(Socket, 9, 1000),
|
||||||
%% DATA frames totaling 90000 bytes of body.
|
%% Send a HEADERS frame initiating a stream followed by
|
||||||
Headers = [
|
%% DATA frames totaling 90000 bytes of body.
|
||||||
{<<":method">>, <<"POST">>},
|
Headers = [
|
||||||
{<<":scheme">>, <<"http">>},
|
{<<":method">>, <<"POST">>},
|
||||||
{<<":authority">>, <<"localhost">>}, %% @todo Correct port number.
|
{<<":scheme">>, <<"http">>},
|
||||||
{<<":path">>, <<"/long_polling">>}
|
{<<":authority">>, <<"localhost">>}, %% @todo Correct port number.
|
||||||
],
|
{<<":path">>, <<"/long_polling">>}
|
||||||
{HeadersBlock, _} = cow_hpack:encode(Headers),
|
],
|
||||||
ok = gen_tcp:send(Socket, [
|
{HeadersBlock, _} = cow_hpack:encode(Headers),
|
||||||
cow_http2:headers(1, nofin, HeadersBlock),
|
ok = gen_tcp:send(Socket, [
|
||||||
cow_http2:data(1, nofin, <<0:15000/unit:8>>),
|
cow_http2:headers(1, nofin, HeadersBlock),
|
||||||
cow_http2:data(1, nofin, <<0:15000/unit:8>>),
|
cow_http2:data(1, nofin, <<0:15000/unit:8>>),
|
||||||
cow_http2:data(1, nofin, <<0:15000/unit:8>>),
|
cow_http2:data(1, nofin, <<0:15000/unit:8>>),
|
||||||
cow_http2:data(1, nofin, <<0:15000/unit:8>>),
|
cow_http2:data(1, nofin, <<0:15000/unit:8>>),
|
||||||
cow_http2:data(1, nofin, <<0:15000/unit:8>>),
|
cow_http2:data(1, nofin, <<0:15000/unit:8>>),
|
||||||
cow_http2:data(1, fin, <<0:15000/unit:8>>)
|
cow_http2:data(1, nofin, <<0:15000/unit:8>>),
|
||||||
]),
|
cow_http2:data(1, fin, <<0:15000/unit:8>>)
|
||||||
%% Receive a FLOW_CONTROL_ERROR stream error.
|
]),
|
||||||
{ok, << _:24, 3:8, _:8, 1:32, 3:32 >>} = gen_tcp:recv(Socket, 13, 6000),
|
%% Receive a FLOW_CONTROL_ERROR stream error.
|
||||||
cowboy:stop_listener(?FUNCTION_NAME).
|
{ok, << _:24, 3:8, _:8, 1:32, 3:32 >>} = gen_tcp:recv(Socket, 13, 6000)
|
||||||
|
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