From f08f4610a08a187c573da2273494a27894bea54c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20Meadows-J=C3=B6nsson?= Date: Wed, 16 May 2018 13:28:49 +0200 Subject: Add streaming without chunking for HTTP/1.1 If content-length is set in the response headers we can skip chunked transfer-encoding. --- test/req_SUITE.erl | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'test/req_SUITE.erl') diff --git a/test/req_SUITE.erl b/test/req_SUITE.erl index 6866123..520bc48 100644 --- a/test/req_SUITE.erl +++ b/test/req_SUITE.erl @@ -146,6 +146,23 @@ do_decode(Headers, Body) -> _ -> Body end. +do_get_error(Path, Config) -> + do_get_error(Path, [], Config). + +do_get_error(Path, Headers, Config) -> + ConnPid = gun_open(Config), + Ref = gun:get(ConnPid, Path, [{<<"accept-encoding">>, <<"gzip">>}|Headers]), + {response, IsFin, Status, RespHeaders} = gun:await(ConnPid, Ref), + Result = case IsFin of + nofin -> gun:await_body(ConnPid, Ref); + fin -> {ok, <<>>} + end, + gun:close(ConnPid), + case Result of + {ok, RespBody} -> {Status, RespHeaders, do_decode(RespHeaders, RespBody)}; + _ -> Result + end. + %% Tests: Request. binding(Config) -> @@ -856,6 +873,38 @@ stream_body_nofin(Config) -> {200, _, <<"Hello world!">>} = do_get("/resp/stream_body/nofin", Config), ok. +stream_body_content_length_multiple(Config) -> + doc("Streamed body via multiple calls."), + {200, _, <<"Hello world!">>} = do_get("/resp/stream_body_content_length/multiple", Config), + ok. + +stream_body_content_length_fin0(Config) -> + doc("Streamed body with last chunk of size 0."), + {200, _, <<"Hello world!">>} = do_get("/resp/stream_body_content_length/fin0", Config), + ok. + +stream_body_content_length_nofin(Config) -> + doc("Unfinished streamed body."), + {200, _, <<"Hello world!">>} = do_get("/resp/stream_body_content_length/nofin", Config), + ok. + +stream_body_content_length_nofin_error(Config) -> + doc("Not all of body sent."), + case config(protocol, Config) of + http -> + case do_get_error("/resp/stream_body_content_length/nofin-error", Config) of + {200, Headers, <<"Hello">>} -> + {_, <<"gzip">>} = lists:keyfind(<<"content-encoding">>, 1, Headers); + {error, {closed, "The connection was lost."}} -> + ok; + {error, timeout} -> + ok + end; + http2 -> + %% @todo HTTP2 should have the same content-length checks + ok + end. + %% @todo Crash when calling stream_body after the fin flag has been set. %% @todo Crash when calling stream_body after calling reply. %% @todo Crash when calling stream_body before calling stream_reply. -- cgit v1.2.3