aboutsummaryrefslogtreecommitdiffstats
path: root/test/http2_SUITE.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2018-01-23 16:14:18 +0100
committerLoïc Hoguin <[email protected]>2018-01-23 16:14:18 +0100
commit482de55a96f9b68664a4d8b638f887138e26c5e8 (patch)
tree896c3398ec12777c7454cb2daef028a0e7a639ab /test/http2_SUITE.erl
parent3a7b411143db08cb4d8813d00988c07848738bd3 (diff)
downloadcowboy-482de55a96f9b68664a4d8b638f887138e26c5e8.tar.gz
cowboy-482de55a96f9b68664a4d8b638f887138e26c5e8.tar.bz2
cowboy-482de55a96f9b68664a4d8b638f887138e26c5e8.zip
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.
Diffstat (limited to 'test/http2_SUITE.erl')
-rw-r--r--test/http2_SUITE.erl30
1 files changed, 24 insertions, 6 deletions
diff --git a/test/http2_SUITE.erl b/test/http2_SUITE.erl
index 7730b58..8ffe2fd 100644
--- a/test/http2_SUITE.erl
+++ b/test/http2_SUITE.erl
@@ -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).