examples/chunked_hello_world/src/toppage_h.erl
raw| 1 | %% Feel free to use, reuse and abuse the code in this file. |
| 2 | |
| 3 | %% @doc Chunked hello world handler. |
| 4 | -module(toppage_h). |
| 5 | |
| 6 | -export([init/2]). |
| 7 | |
| 8 | init(Req0, Opts) -> |
| 9 | Req = cowboy_req:stream_reply(200, Req0), |
| 10 | cowboy_req:stream_body("Hello\r\n", nofin, Req), |
| 11 | timer:sleep(1000), |
| 12 | cowboy_req:stream_body("World\r\n", nofin, Req), |
| 13 | timer:sleep(1000), |
| 14 | cowboy_req:stream_body("Chunked!\r\n", fin, Req), |
| 15 | {ok, Req, Opts}. |