loop_handler_abort_h.erl 525 B

123456789101112131415161718192021
  1. %% This module implements a loop handler that reads
  2. %% 1000 bytes of the request body after sending itself
  3. %% a message, then terminates the stream.
  4. -module(loop_handler_abort_h).
  5. -export([init/2]).
  6. -export([info/3]).
  7. -export([terminate/3]).
  8. init(Req, _) ->
  9. self() ! timeout,
  10. {cowboy_loop, Req, undefined, hibernate}.
  11. info(timeout, Req0, State) ->
  12. {_Status, Body, Req} = cowboy_req:read_body(Req0, #{length => 1000}),
  13. 1000 = byte_size(Body),
  14. {stop, cowboy_req:reply(200, Req), State}.
  15. terminate(stop, _, _) ->
  16. ok.