chunked_handler.erl 473 B

12345678910111213141516171819
  1. %% Feel free to use, reuse and abuse the code in this file.
  2. -module(chunked_handler).
  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. {ok, Req2} = cowboy_req:chunked_reply(200, Req),
  9. timer:sleep(100),
  10. cowboy_req:chunk("chunked_handler\r\n", Req2),
  11. timer:sleep(100),
  12. cowboy_req:chunk("works fine!", Req2),
  13. {ok, Req2, State}.
  14. terminate(_, _, _) ->
  15. ok.