From 4cbdfdd293c687212f9ce64e608de838ec74a592 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Sun, 5 Feb 2017 13:45:35 +0100 Subject: Fix sending of large files with HTTP/2 Also finish implementing the relevant test, getting rid of todos. --- test/static_handler_SUITE.erl | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'test') diff --git a/test/static_handler_SUITE.erl b/test/static_handler_SUITE.erl index 7a6517f..95d6d75 100644 --- a/test/static_handler_SUITE.erl +++ b/test/static_handler_SUITE.erl @@ -391,13 +391,30 @@ dir_html(Config) -> {_, <<"text/html">>} = lists:keyfind(<<"content-type">>, 1, Headers), ok. -%% @todo This test results in a crash dump. -%dir_large_file(Config) -> -% doc("Get a large file."), -% {200, Headers, _} = do_get(config(prefix, Config) ++ "/large.bin", Config), -% {_, <<"text/html">>} = lists:keyfind(<<"content-type">>, 1, Headers), -%% @todo Receive body. -% ok. +dir_large_file(Config) -> + doc("Get a large file."), + ConnPid = gun_open(Config), + Ref = gun:get(ConnPid, config(prefix, Config) ++ "/large.bin", + [{<<"accept-encoding">>, <<"gzip">>}]), + {response, nofin, 200, RespHeaders} = gun:await(ConnPid, Ref), + {_, <<"application/octet-stream">>} = lists:keyfind(<<"content-type">>, 1, RespHeaders), + Size = 512*1024*1024, + {ok, Size} = do_dir_large_file(ConnPid, Ref, 0), + ok. + +do_dir_large_file(ConnPid, Ref, N) -> + receive + {gun_data, ConnPid, Ref, nofin, Data} -> + do_dir_large_file(ConnPid, Ref, N + byte_size(Data)); + {gun_data, ConnPid, Ref, fin, Data} -> + {ok, N + byte_size(Data)}; + {gun_error, ConnPid, Ref, Reason} -> + {error, Reason}; + {gun_error, ConnPid, Reason} -> + {error, Reason} + after 5000 -> + {error, timeout} + end. dir_text(Config) -> doc("Get a .txt file. The extension is unknown by default."), -- cgit v1.2.3