2011-04-08 16:30:37 +02:00
|
|
|
%% Feel free to use, reuse and abuse the code in this file.
|
|
|
|
|
|
|
|
-module(http_handler).
|
|
|
|
-behaviour(cowboy_http_handler).
|
2013-01-22 02:34:18 +01:00
|
|
|
-export([init/3, handle/2, terminate/3]).
|
2011-04-08 16:30:37 +02:00
|
|
|
|
2011-04-14 01:26:02 +02:00
|
|
|
-record(state, {headers, body}).
|
2011-04-08 16:30:37 +02:00
|
|
|
|
2011-04-14 01:26:02 +02:00
|
|
|
init({_Transport, http}, Req, Opts) ->
|
|
|
|
Headers = proplists:get_value(headers, Opts, []),
|
|
|
|
Body = proplists:get_value(body, Opts, "http_handler"),
|
|
|
|
{ok, Req, #state{headers=Headers, body=Body}}.
|
|
|
|
|
|
|
|
handle(Req, State=#state{headers=Headers, body=Body}) ->
|
2014-09-23 16:43:29 +03:00
|
|
|
{ok, cowboy_req:reply(200, Headers, Body, Req), State}.
|
2011-04-08 16:30:37 +02:00
|
|
|
|
2013-01-22 02:34:18 +01:00
|
|
|
terminate(_, _, _) ->
|
2011-04-08 16:30:37 +02:00
|
|
|
ok.
|