http_streamed.erl 442 B

123456789101112131415161718
  1. %% Feel free to use, reuse and abuse the code in this file.
  2. -module(http_streamed).
  3. -export([init/2]).
  4. -export([handle/2]).
  5. init(Req, Opts) ->
  6. {http, Req, Opts}.
  7. handle(Req, State) ->
  8. Req2 = cowboy_req:set([{resp_state, waiting_stream}], Req),
  9. Req3 = cowboy_req:chunked_reply(200, Req2),
  10. timer:sleep(100),
  11. cowboy_req:chunk("streamed_handler\r\n", Req3),
  12. timer:sleep(100),
  13. cowboy_req:chunk("works fine!", Req3),
  14. {ok, Req3, State}.