-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
5 changed files
with
225 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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). |
Oops, something went wrong.