http_streamed.erl 534 B

1234567891011121314151617181920
  1. %% Feel free to use, reuse and abuse the code in this file.
  2. -module(http_streamed).
  3. -behaviour(cowboy_http_handler).
  4. -export([init/3, handle/2, terminate/3]).
  5. init({_Transport, http}, Req, _Opts) ->
  6. {ok, Req, undefined}.
  7. handle(Req, State) ->
  8. Req2 = cowboy_req:set([{resp_state, waiting_stream}], Req),
  9. {ok, 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}.
  15. terminate(_, _, _) ->
  16. ok.