toppage_handler.erl 384 B

123456789101112131415
  1. %% Feel free to use, reuse and abuse the code in this file.
  2. %% @doc Chunked hello world handler.
  3. -module(toppage_handler).
  4. -export([init/2]).
  5. init(Req, Opts) ->
  6. Req2 = cowboy_req:chunked_reply(200, Req),
  7. cowboy_req:chunk("Hello\r\n", Req2),
  8. timer:sleep(1000),
  9. cowboy_req:chunk("World\r\n", Req2),
  10. timer:sleep(1000),
  11. cowboy_req:chunk("Chunked!\r\n", Req2),
  12. {ok, Req2, Opts}.