loop_handler_timeout_h.erl 615 B

12345678910111213141516171819202122
  1. %% This module implements a loop handler that sends
  2. %% itself a timeout that will intentionally arrive
  3. %% after the HTTP/1.1 request_timeout. The protocol
  4. %% is not supposed to close the connection when a
  5. %% request is ongoing, and therefore this handler
  6. %% will eventually send a 200 reply.
  7. -module(loop_handler_timeout_h).
  8. -export([init/2]).
  9. -export([info/3]).
  10. -export([terminate/3]).
  11. init(Req, _) ->
  12. erlang:send_after(6000, self(), timeout),
  13. {cowboy_loop, Req, #{hibernate => true}}.
  14. info(timeout, Req, State) ->
  15. {stop, cowboy_req:reply(200, #{}, <<"Good!">>, Req), State}.
  16. terminate(stop, _, _) ->
  17. ok.