| 1 |
%% This module implements a loop handler that reads |
| 2 |
%% the request body after sending itself a message, |
| 3 |
%% checks that its size is exactly 100000 bytes, |
| 4 |
%% then sends a 200 reply back. |
| 5 |
|
| 6 |
-module(loop_handler_body_h). |
| 7 |
|
| 8 |
-export([init/2]). |
| 9 |
-export([info/3]). |
| 10 |
-export([terminate/3]). |
| 11 |
|
| 12 |
init(Req, _) -> |
| 13 |
self() ! timeout, |
| 14 |
{cowboy_loop, Req, undefined, hibernate}. |
| 15 |
|
| 16 |
info(timeout, Req0, State) -> |
| 17 |
{ok, Body, Req} = cowboy_req:read_body(Req0), |
| 18 |
100000 = byte_size(Body), |
| 19 |
{stop, cowboy_req:reply(200, Req), State}. |
| 20 |
|
| 21 |
terminate(stop, _, _) -> |
| 22 |
ok. |