toppage_handler.erl 559 B

1234567891011121314151617181920212223
  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/3]).
  5. -export([handle/2]).
  6. -export([terminate/3]).
  7. init(_Transport, Req, []) ->
  8. {ok, Req, undefined}.
  9. handle(Req, State) ->
  10. {ok, Req2} = cowboy_req:chunked_reply(200, Req),
  11. ok = cowboy_req:chunk("Hello\r\n", Req2),
  12. ok = timer:sleep(1000),
  13. ok = cowboy_req:chunk("World\r\n", Req2),
  14. ok = timer:sleep(1000),
  15. ok = cowboy_req:chunk("Chunked!\r\n", Req2),
  16. {ok, Req2, State}.
  17. terminate(_Reason, _Req, _State) ->
  18. ok.