1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
%% This module implements a loop handler that sends
%% itself a timeout that will intentionally arrive
%% 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.
-module(loop_handler_timeout_h).
-export([init/2]).
-export([info/3]).
-export([terminate/3]).
init(Req, _) ->
erlang:send_after(6000, self(), timeout),
{cowboy_loop, Req, #{hibernate => true}}.
info(timeout, Req, State) ->
{stop, cowboy_req:reply(200, #{}, <<"Good!">>, Req), State}.
terminate(stop, _, _) ->
ok.
|