0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-16 05:00:24 +00:00
cowboy/examples/cookie/src/toppage_handler.erl
Loïc Hoguin 91ae70b06c
Change the order of set_resp_cookie arguments
The Opts value is put last, to be more consistent with the
rest of the cowboy_req module.

Additionally a test handler was fixed which reduced the number
of errors in http_SUITE.
2017-02-19 09:46:11 +01:00

21 lines
619 B
Erlang

%% Feel free to use, reuse and abuse the code in this file.
%% @doc Cookie handler.
-module(toppage_handler).
-export([init/2]).
init(Req0, Opts) ->
NewValue = integer_to_list(rand:uniform(1000000)),
Req1 = cowboy_req:set_resp_cookie(<<"server">>, NewValue,
Req0, #{path => <<"/">>}),
#{client := ClientCookie, server := ServerCookie}
= cowboy_req:match_cookies([{client, [], <<>>}, {server, [], <<>>}], Req1),
{ok, Body} = toppage_dtl:render([
{client, ClientCookie},
{server, ServerCookie}
]),
Req = cowboy_req:reply(200, #{
<<"content-type">> => <<"text/html">>
}, Body, Req1),
{ok, Req, Opts}.