Debian Codegraph @

test/handlers/loop_handler_abort_h.erl

raw
1 %% This module implements a loop handler that reads
2 %% 1000 bytes of the request body after sending itself
3 %% a message, then terminates the stream.
4
5 -module(loop_handler_abort_h).
6
7 -export([init/2]).
8 -export([info/3]).
9 -export([terminate/3]).
10
11 init(Req, _) ->
12 self() ! timeout,
13 {cowboy_loop, Req, undefined, hibernate}.
14
15 info(timeout, Req0, State) ->
16 {_Status, Body, Req} = cowboy_req:read_body(Req0, #{length => 1000}),
17 1000 = byte_size(Body),
18 {stop, cowboy_req:reply(200, Req), State}.
19
20 terminate(stop, _, _) ->
21 ok.