2012-12-20 14:40:22 +01:00
|
|
|
%% Feel free to use, reuse and abuse the code in this file.
|
|
|
|
|
|
|
|
%% @doc Cookie handler.
|
|
|
|
-module(toppage_handler).
|
|
|
|
|
|
|
|
-export([init/3]).
|
|
|
|
-export([handle/2]).
|
2013-01-22 02:34:18 +01:00
|
|
|
-export([terminate/3]).
|
2012-12-20 14:40:22 +01:00
|
|
|
|
|
|
|
init(_Transport, Req, []) ->
|
|
|
|
{ok, Req, undefined}.
|
|
|
|
|
|
|
|
handle(Req, State) ->
|
|
|
|
NewValue = integer_to_list(random:uniform(1000000)),
|
|
|
|
Req2 = cowboy_req:set_resp_cookie(
|
|
|
|
<<"server">>, NewValue, [{path, <<"/">>}], Req),
|
2014-09-23 16:43:29 +03:00
|
|
|
#{client := ClientCookie, server := ServerCookie}
|
|
|
|
= cowboy_req:match_cookies(Req2, [client, server]),
|
2012-12-20 14:40:22 +01:00
|
|
|
{ok, Body} = toppage_dtl:render([
|
|
|
|
{client, ClientCookie},
|
|
|
|
{server, ServerCookie}
|
|
|
|
]),
|
2014-09-23 16:43:29 +03:00
|
|
|
Req3 = cowboy_req:reply(200,
|
2012-12-20 14:40:22 +01:00
|
|
|
[{<<"content-type">>, <<"text/html">>}],
|
2014-09-23 16:43:29 +03:00
|
|
|
Body, Req2),
|
|
|
|
{ok, Req3, State}.
|
2012-12-20 14:40:22 +01:00
|
|
|
|
2013-01-22 02:34:18 +01:00
|
|
|
terminate(_Reason, _Req, _State) ->
|
2012-12-20 14:40:22 +01:00
|
|
|
ok.
|