loop_handler_body_h.erl 550 B

1234567891011121314151617181920212223
  1. %% This module implements a loop handler that reads
  2. %% the request body after sending itself a message,
  3. %% checks that its size is exactly 100000 bytes,
  4. %% then sends a 200 reply back.
  5. -module(loop_handler_body_h).
  6. -export([init/2]).
  7. -export([info/3]).
  8. -export([terminate/3]).
  9. init(Req, _) ->
  10. self() ! timeout,
  11. {cowboy_loop, Req, undefined, 5000, hibernate}.
  12. info(timeout, Req, State) ->
  13. {ok, Body, Req2} = cowboy_req:read_body(Req),
  14. 100000 = byte_size(Body),
  15. cowboy_req:reply(200, Req2),
  16. {stop, Req, State}.
  17. terminate(stop, _, _) ->
  18. ok.