2014-04-26 13:46:55 +02:00
|
|
|
%% This module implements a loop handler that reads
|
|
|
|
%% the request body after sending itself a message,
|
|
|
|
%% checks that its size is exactly 100000 bytes,
|
|
|
|
%% then sends a 200 reply back.
|
|
|
|
|
|
|
|
-module(loop_handler_body_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, _) ->
|
2014-04-26 13:46:55 +02:00
|
|
|
self() ! timeout,
|
2014-09-30 20:12:13 +03:00
|
|
|
{cowboy_loop, Req, undefined, 5000, hibernate}.
|
2014-04-26 13:46:55 +02:00
|
|
|
|
|
|
|
info(timeout, Req, State) ->
|
|
|
|
{ok, Body, Req2} = cowboy_req:body(Req),
|
|
|
|
100000 = byte_size(Body),
|
2014-09-30 20:12:13 +03:00
|
|
|
{shutdown, cowboy_req:reply(200, Req2), State}.
|
2014-04-26 13:46:55 +02:00
|
|
|
|
2014-09-30 20:12:13 +03:00
|
|
|
terminate(shutdown, _, _) ->
|
2014-04-26 13:46:55 +02:00
|
|
|
ok.
|