chunked_handler.erl 455 B

1234567891011121314151617
  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/2]).
  5. init({_Transport, http}, Req, _Opts) ->
  6. {ok, Req, undefined}.
  7. handle(Req, State) ->
  8. {ok, Req2} = cowboy_http_req:chunked_reply(200, Req),
  9. cowboy_http_req:chunk("chunked_handler\r\n", Req2),
  10. cowboy_http_req:chunk("works fine!", Req2),
  11. {ok, Req2, State}.
  12. terminate(_Req, _State) ->
  13. ok.