2014-04-26 13:46:55 +02:00
|
|
|
%% This module implements a loop handler that sends
|
|
|
|
%% itself a timeout that will intentionally arrive
|
2017-05-03 17:44:00 +02:00
|
|
|
%% after the HTTP/1.1 request_timeout. The protocol
|
|
|
|
%% is not supposed to close the connection when a
|
|
|
|
%% request is ongoing, and therefore this handler
|
|
|
|
%% will eventually send a 200 reply.
|
2014-04-26 13:46:55 +02:00
|
|
|
|
|
|
|
-module(loop_handler_timeout_h).
|
|
|
|
|
2014-09-26 15:58:44 +03:00
|
|
|
-export([init/2]).
|
2014-04-26 13:46:55 +02:00
|
|
|
-export([info/3]).
|
|
|
|
-export([terminate/3]).
|
|
|
|
|
2014-09-26 15:58:44 +03:00
|
|
|
init(Req, _) ->
|
2017-05-03 17:44:00 +02:00
|
|
|
erlang:send_after(6000, self(), timeout),
|
|
|
|
{cowboy_loop, Req, #{hibernate => true}}.
|
2014-04-26 13:46:55 +02:00
|
|
|
|
|
|
|
info(timeout, Req, State) ->
|
2017-05-03 17:44:00 +02:00
|
|
|
{stop, cowboy_req:reply(200, #{}, <<"Good!">>, Req), State}.
|
2014-04-26 13:46:55 +02:00
|
|
|
|
2017-05-03 17:44:00 +02:00
|
|
|
terminate(stop, _, _) ->
|
2014-04-26 13:46:55 +02:00
|
|
|
ok.
|