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).
|
|
|
|
|
2014-09-26 15:58:44 +03:00
|
|
|
-export([init/2]).
|
2012-12-20 14:40:22 +01:00
|
|
|
|
2016-08-10 17:15:02 +02:00
|
|
|
init(Req0, Opts) ->
|
2016-06-14 16:23:51 +02:00
|
|
|
NewValue = integer_to_list(rand:uniform(1000000)),
|
2016-08-10 17:15:02 +02:00
|
|
|
Req1 = cowboy_req:set_resp_cookie(<<"server">>, NewValue,
|
|
|
|
#{path => <<"/">>}, Req0),
|
2014-09-23 16:43:29 +03:00
|
|
|
#{client := ClientCookie, server := ServerCookie}
|
2016-08-11 11:25:58 +02:00
|
|
|
= cowboy_req:match_cookies([{client, [], <<>>}, {server, [], <<>>}], Req1),
|
2012-12-20 14:40:22 +01:00
|
|
|
{ok, Body} = toppage_dtl:render([
|
|
|
|
{client, ClientCookie},
|
|
|
|
{server, ServerCookie}
|
|
|
|
]),
|
2016-08-10 17:15:02 +02:00
|
|
|
Req = cowboy_req:reply(200, #{
|
2016-06-14 16:23:51 +02:00
|
|
|
<<"content-type">> => <<"text/html">>
|
2016-08-10 17:15:02 +02:00
|
|
|
}, Body, Req1),
|
2016-08-11 11:25:58 +02:00
|
|
|
{ok, Req, Opts}.
|