loop_handler_timeout_h.erl 574 B

123456789101112131415161718192021
  1. %% This module implements a loop handler that sends
  2. %% itself a timeout that will intentionally arrive
  3. %% too late, as it configures itself to only wait
  4. %% 200ms before closing the connection in init/2.
  5. %% This results in a 204 reply being sent back by Cowboy.
  6. -module(loop_handler_timeout_h).
  7. -export([init/2]).
  8. -export([info/3]).
  9. -export([terminate/3]).
  10. init(Req, _) ->
  11. erlang:send_after(1000, self(), timeout),
  12. {cowboy_loop, Req, undefined, 200, hibernate}.
  13. info(timeout, Req, State) ->
  14. {stop, cowboy_req:reply(500, Req), State}.
  15. terminate(timeout, _, _) ->
  16. ok.