2011-05-08 17:26:21 +02:00
|
|
|
%% Feel free to use, reuse and abuse the code in this file.
|
|
|
|
|
2013-04-24 20:28:44 +02:00
|
|
|
-module(http_chunked).
|
2011-05-08 17:26:21 +02:00
|
|
|
|
2014-09-26 15:58:44 +03:00
|
|
|
-export([init/2]).
|
|
|
|
|
|
|
|
init(Req, Opts) ->
|
2017-07-14 19:09:42 +02:00
|
|
|
Req2 = cowboy_req:stream_reply(200, Req),
|
2015-02-16 19:49:01 +01:00
|
|
|
%% Try an empty chunk to make sure the stream doesn't get closed.
|
2017-07-14 19:09:42 +02:00
|
|
|
cowboy_req:stream_body([<<>>], nofin, Req2),
|
2013-01-22 14:22:28 +01:00
|
|
|
timer:sleep(100),
|
2017-07-14 19:09:42 +02:00
|
|
|
cowboy_req:stream_body("chunked_handler\r\n", nofin, Req2),
|
2013-01-22 14:22:28 +01:00
|
|
|
timer:sleep(100),
|
2017-07-14 19:09:42 +02:00
|
|
|
cowboy_req:stream_body("works fine!", fin, Req2),
|
2014-09-30 20:12:13 +03:00
|
|
|
{ok, Req2, Opts}.
|