loop_handler_body_h.erl 600 B

123456789101112131415161718192021222324
  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. -behaviour(cowboy_loop_handler).
  7. -export([init/3]).
  8. -export([info/3]).
  9. -export([terminate/3]).
  10. init(_, Req, _) ->
  11. self() ! timeout,
  12. {loop, Req, undefined, 5000, hibernate}.
  13. info(timeout, Req, State) ->
  14. {ok, Body, Req2} = cowboy_req:body(Req),
  15. 100000 = byte_size(Body),
  16. {ok, Req3} = cowboy_req:reply(200, Req2),
  17. {ok, Req3, State}.
  18. terminate({normal, shutdown}, _, _) ->
  19. ok.