2012-07-21 21:46:21 +02:00
|
|
|
%% Feel free to use, reuse and abuse the code in this file.
|
|
|
|
|
|
|
|
%% @doc GET echo handler.
|
|
|
|
-module(toppage_handler).
|
|
|
|
|
|
|
|
-export([init/3]).
|
|
|
|
-export([handle/2]).
|
|
|
|
-export([terminate/2]).
|
|
|
|
|
|
|
|
init(_Transport, Req, []) ->
|
|
|
|
{ok, Req, undefined}.
|
|
|
|
|
|
|
|
handle(Req, State) ->
|
2012-08-27 13:28:57 +02:00
|
|
|
{Method, Req2} = cowboy_req:method(Req),
|
|
|
|
{Echo, Req3} = cowboy_req:qs_val(<<"echo">>, Req2),
|
2012-07-21 21:46:21 +02:00
|
|
|
{ok, Req4} = echo(Method, Echo, Req3),
|
|
|
|
{ok, Req4, State}.
|
|
|
|
|
2012-09-20 06:22:51 +02:00
|
|
|
echo(<<"GET">>, undefined, Req) ->
|
2012-08-27 13:28:57 +02:00
|
|
|
cowboy_req:reply(400, [], <<"Missing echo parameter.">>, Req);
|
2012-09-20 06:22:51 +02:00
|
|
|
echo(<<"GET">>, Echo, Req) ->
|
2012-08-27 13:28:57 +02:00
|
|
|
cowboy_req:reply(200,
|
2012-07-21 21:46:21 +02:00
|
|
|
[{<<"Content-Encoding">>, <<"utf-8">>}], Echo, Req);
|
|
|
|
echo(_, _, Req) ->
|
|
|
|
%% Method not allowed.
|
2012-08-27 13:28:57 +02:00
|
|
|
cowboy_req:reply(405, Req).
|
2012-07-21 21:46:21 +02:00
|
|
|
|
|
|
|
terminate(_Req, _State) ->
|
|
|
|
ok.
|