loop_handler_body_h.erl 538 B

12345678910111213141516171819202122
  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, hibernate}.
  12. info(timeout, Req0, State) ->
  13. {ok, Body, Req} = cowboy_req:read_body(Req0),
  14. 100000 = byte_size(Body),
  15. {stop, cowboy_req:reply(200, Req), State}.
  16. terminate(stop, _, _) ->
  17. ok.