0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 12:20:24 +00:00

Fix cookie example

This commit is contained in:
Loïc Hoguin 2016-06-14 16:23:51 +02:00
parent a55679b231
commit 84fb85e2e4
3 changed files with 26 additions and 8 deletions

View file

@ -16,9 +16,9 @@ start(_Type, _Args) ->
{'_', toppage_handler, []} {'_', toppage_handler, []}
]} ]}
]), ]),
{ok, _} = cowboy:start_http(http, 100, [{port, 8080}], [ {ok, _} = cowboy:start_clear(http, 100, [{port, 8080}], #{
{env, [{dispatch, Dispatch}]} env => #{dispatch => Dispatch}
]), }),
cookie_sup:start_link(). cookie_sup:start_link().
stop(_State) -> stop(_State) ->

View file

@ -6,7 +6,7 @@
-export([init/2]). -export([init/2]).
init(Req, Opts) -> init(Req, Opts) ->
NewValue = integer_to_list(random:uniform(1000000)), NewValue = integer_to_list(rand:uniform(1000000)),
Req2 = cowboy_req:set_resp_cookie( Req2 = cowboy_req:set_resp_cookie(
<<"server">>, NewValue, [{path, <<"/">>}], Req), <<"server">>, NewValue, [{path, <<"/">>}], Req),
#{client := ClientCookie, server := ServerCookie} #{client := ClientCookie, server := ServerCookie}
@ -15,7 +15,7 @@ init(Req, Opts) ->
{client, ClientCookie}, {client, ClientCookie},
{server, ServerCookie} {server, ServerCookie}
]), ]),
Req3 = cowboy_req:reply(200, cowboy_req:reply(200, #{
[{<<"content-type">>, <<"text/html">>}], <<"content-type">> => <<"text/html">>
Body, Req2), }, Body, Req2),
{ok, Req3, Opts}. {ok, Req2, Opts}.

View file

@ -135,6 +135,24 @@ do_chunked_hello_world(Transport, Protocol, Config) ->
ok ok
end. end.
%% Cookie.
cookie(Config) ->
doc("Cookie example."),
try
do_compile_and_start(cookie),
do_cookie(tcp, http, Config),
do_cookie(tcp, http2, Config)
after
do_stop(cookie)
end.
do_cookie(Transport, Protocol, Config) ->
{200, _, One} = do_get(Transport, Protocol, "/", Config),
{200, _, Two} = do_get(Transport, Protocol, "/", [{<<"cookie">>, <<"server=abcdef">>}], Config),
true = One =/= Two,
ok.
%% Echo GET. %% Echo GET.
echo_get(Config) -> echo_get(Config) ->