aboutsummaryrefslogtreecommitdiffstats
path: root/test/handlers/cookie_parser_result_h.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2020-03-11 19:45:16 +0100
committerLoïc Hoguin <[email protected]>2020-03-12 18:08:16 +0100
commit87d0bfff926892d2dc0a55a3dc45d8c5f8a682f3 (patch)
tree5b381d3d2c2f691699baeddad78c781026d237b7 /test/handlers/cookie_parser_result_h.erl
parent04790d3a281a42fbd65c9a44fe88f437cfe025f3 (diff)
downloadgun-87d0bfff926892d2dc0a55a3dc45d8c5f8a682f3.tar.gz
gun-87d0bfff926892d2dc0a55a3dc45d8c5f8a682f3.tar.bz2
gun-87d0bfff926892d2dc0a55a3dc45d8c5f8a682f3.zip
Make Gun use the cookie store when configured to
Diffstat (limited to 'test/handlers/cookie_parser_result_h.erl')
-rw-r--r--test/handlers/cookie_parser_result_h.erl25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/handlers/cookie_parser_result_h.erl b/test/handlers/cookie_parser_result_h.erl
new file mode 100644
index 0000000..a1fa899
--- /dev/null
+++ b/test/handlers/cookie_parser_result_h.erl
@@ -0,0 +1,25 @@
+%% Feel free to use, reuse and abuse the code in this file.
+
+-module(cookie_parser_result_h).
+
+-export([init/2]).
+
+init(Req=#{qs := Qs}, State) ->
+ %% Hardcoded path, but I doubt it's going to break anytime soon.
+ ExpectedFile = iolist_to_binary(["../../test/wpt/cookies/", Qs, "-expected"]),
+ CookieHd = cowboy_req:header(<<"cookie">>, Req),
+ case file:read_file(ExpectedFile) of
+ {ok, Expected} when Expected =:= <<>>; Expected =:= <<"\n">> ->
+ undefined = CookieHd,
+ ok;
+ {ok, <<"Cookie: ",CookiesBin0/bits>>} ->
+ %% We only care about the first line.
+ [CookiesBin, <<>>|_] = string:split(CookiesBin0, <<"\n">>, all),
+ CookiesBin = CookieHd,
+ ok
+ end,
+ %% We echo back the cookie header in order to log it.
+ {ok, cowboy_req:reply(204, case CookieHd of
+ undefined -> #{<<"x-no-cookie-received">> => <<"Cookie header missing.">>};
+ _ -> #{<<"x-cookie-received">> => CookieHd}
+ end, Req), State}.