mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 12:20:24 +00:00
Fix a miscount of output flow control window for HTTP/2
The miscount occurred because of a faulty iolist split function. The bug should now be corrected, a PropEr test has been added and a regression test has also been added.
This commit is contained in:
parent
3a7b411143
commit
482de55a96
4 changed files with 445 additions and 9 deletions
|
@ -18,6 +18,7 @@
|
|||
|
||||
-import(ct_helper, [config/2]).
|
||||
-import(ct_helper, [doc/1]).
|
||||
-import(cowboy_test, [gun_open/1]).
|
||||
|
||||
all() -> [{group, clear}].
|
||||
|
||||
|
@ -25,7 +26,8 @@ groups() -> [{clear, [parallel], ct_helper:all(?MODULE)}].
|
|||
|
||||
init_routes(_) -> [
|
||||
{"localhost", [
|
||||
{"/", hello_h, []}
|
||||
{"/", hello_h, []},
|
||||
{"/resp_iolist_body", resp_iolist_body_h, []}
|
||||
]}
|
||||
].
|
||||
|
||||
|
@ -45,16 +47,32 @@ do_handshake(Config) ->
|
|||
|
||||
inactivity_timeout(Config) ->
|
||||
doc("Terminate when the inactivity timeout is reached"),
|
||||
Ref = inactivity_timeout_listener,
|
||||
ProtoOpts = #{
|
||||
env => #{dispatch => cowboy_router:compile(init_routes(Config))},
|
||||
inactivity_timeout => 1000
|
||||
},
|
||||
{ok, _} = cowboy:start_clear(Ref, [{port, 0}], ProtoOpts),
|
||||
Port = ranch:get_port(Ref),
|
||||
SocketConfig = [{type, tcp}, {protocol, http}, {port, Port}, {opts, []}|Config],
|
||||
{ok, Socket} = do_handshake(SocketConfig),
|
||||
{ok, _} = cowboy:start_clear(inactivity_timeout, [{port, 0}], ProtoOpts),
|
||||
Port = ranch:get_port(inactivity_timeout),
|
||||
{ok, Socket} = do_handshake([{port, Port}|Config]),
|
||||
receive after 1000 -> ok end,
|
||||
%% Receive a GOAWAY frame back with an INTERNAL_ERROR.
|
||||
{ok, << _:24, 7:8, _:72, 2:32 >>} = gen_tcp:recv(Socket, 17, 1000),
|
||||
ok.
|
||||
|
||||
resp_iolist_body(Config) ->
|
||||
doc("Regression test when response bodies are iolists that "
|
||||
"include improper lists, empty lists and empty binaries. "
|
||||
"The original issue failed to split the body into frames properly."),
|
||||
ProtoOpts = #{
|
||||
env => #{dispatch => cowboy_router:compile(init_routes(Config))}
|
||||
},
|
||||
{ok, _} = cowboy:start_clear(resp_iolist_body, [{port, 0}], ProtoOpts),
|
||||
Port = ranch:get_port(resp_iolist_body),
|
||||
ConnPid = gun_open([{type, tcp}, {protocol, http2}, {port, Port}|Config]),
|
||||
Ref = gun:get(ConnPid, "/resp_iolist_body"),
|
||||
{response, nofin, 200, RespHeaders} = gun:await(ConnPid, Ref),
|
||||
{_, BinLen} = lists:keyfind(<<"content-length">>, 1, RespHeaders),
|
||||
Len = binary_to_integer(BinLen),
|
||||
{ok, RespBody} = gun:await_body(ConnPid, Ref),
|
||||
Len = iolist_size(RespBody),
|
||||
gun:close(ConnPid).
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue