0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 12:20:24 +00:00

Fix sending of large files with HTTP/2

Also finish implementing the relevant test, getting rid of todos.
This commit is contained in:
Loïc Hoguin 2017-02-05 13:45:35 +01:00
parent f4fddbd0a1
commit 4cbdfdd293
No known key found for this signature in database
GPG key ID: 71366FF21851DF03
2 changed files with 44 additions and 9 deletions

View file

@ -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."),