aboutsummaryrefslogtreecommitdiffstats
path: root/test/handlers/streamed_result_h.erl
diff options
context:
space:
mode:
authorRobert J. Macomber <[email protected]>2021-02-08 16:05:05 -0800
committerLoïc Hoguin <[email protected]>2023-12-21 14:03:07 +0100
commitf74b69c3edd6e8c8891a3a8e18d14c8ae93bf5c4 (patch)
treef823cd1f7d21bc3bd86bd9a59d27edde60d8631e /test/handlers/streamed_result_h.erl
parent7400b04b02b2ab37ee8bd679e21678945e631552 (diff)
downloadcowboy-f74b69c3edd6e8c8891a3a8e18d14c8ae93bf5c4.tar.gz
cowboy-f74b69c3edd6e8c8891a3a8e18d14c8ae93bf5c4.tar.bz2
cowboy-f74b69c3edd6e8c8891a3a8e18d14c8ae93bf5c4.zip
Optionally reset the idle timeout when sending data
A new option reset_idle_timeout_on_send has been added. When set to 'true', the idle timeout is reset not only when data is received, but also when data is sent. This allows sending large responses without having to worry about timeouts triggering. The default is currently unchanged but might change in a future release. LH: Greatly reworked the implementation so that the timeout gets reset on almost all socket writes. This essentially completely supersets the original work. Tests are mostly the same although I refactored a bit to avoid test code duplication. This commit also changes HTTP/2 behavior a little when data is received: Cowboy will not attempt to update the window before running stream handler commands to avoid sending WINDOW_UPDATE frames twice. Now it has some small heuristic to ensure they can only be sent once at most.
Diffstat (limited to 'test/handlers/streamed_result_h.erl')
-rw-r--r--test/handlers/streamed_result_h.erl20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/handlers/streamed_result_h.erl b/test/handlers/streamed_result_h.erl
new file mode 100644
index 0000000..ea6f492
--- /dev/null
+++ b/test/handlers/streamed_result_h.erl
@@ -0,0 +1,20 @@
+-module(streamed_result_h).
+
+-export([init/2]).
+
+init(Req, Opts) ->
+ N = list_to_integer(binary_to_list(cowboy_req:binding(n, Req))),
+ Interval = list_to_integer(binary_to_list(cowboy_req:binding(interval, Req))),
+ chunked(N, Interval, Req, Opts).
+
+chunked(N, Interval, Req0, Opts) ->
+ Req = cowboy_req:stream_reply(200, Req0),
+ {ok, loop(N, Interval, Req), Opts}.
+
+loop(0, _Interval, Req) ->
+ ok = cowboy_req:stream_body("Finished!\n", fin, Req),
+ Req;
+loop(N, Interval, Req) ->
+ ok = cowboy_req:stream_body(iolist_to_binary([integer_to_list(N), <<"\n">>]), nofin, Req),
+ timer:sleep(Interval),
+ loop(N-1, Interval, Req).