aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKrzysztof Jurewicz <[email protected]>2015-07-21 11:10:47 +0200
committerKrzysztof Jurewicz <[email protected]>2015-07-21 11:10:47 +0200
commitf9a630232f534ce295f4b5eeca8b0124cdb6170e (patch)
treec5e6a5a051386d58e32822919d685b72c4a3d7d3
parentfd4ef5409026bfce933d4f587b96d2c1c156f549 (diff)
downloadcowlib-f9a630232f534ce295f4b5eeca8b0124cdb6170e.tar.gz
cowlib-f9a630232f534ce295f4b5eeca8b0124cdb6170e.tar.bz2
cowlib-f9a630232f534ce295f4b5eeca8b0124cdb6170e.zip
Fix handling of default values in cookie options
Previously, an error would be raised when explicitly passing a default value for either “http_only” or “secure” option.
-rw-r--r--src/cow_cookie.erl8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/cow_cookie.erl b/src/cow_cookie.erl
index 150efeb..b31a528 100644
--- a/src/cow_cookie.erl
+++ b/src/cow_cookie.erl
@@ -197,10 +197,12 @@ setcookie(Name, Value, Opts) ->
end,
SecureBin = case lists:keyfind(secure, 1, Opts) of
false -> <<>>;
+ {_, false} -> <<>>;
{_, true} -> <<"; Secure">>
end,
HttpOnlyBin = case lists:keyfind(http_only, 1, Opts) of
false -> <<>>;
+ {_, false} -> <<>>;
{_, true} -> <<"; HttpOnly">>
end,
[Name, <<"=">>, Value, <<"; Version=1">>,
@@ -218,6 +220,12 @@ setcookie_test_() ->
[{path, <<"/acme">>}],
<<"Customer=WILE_E_COYOTE; Version=1; Path=/acme">>},
{<<"Customer">>, <<"WILE_E_COYOTE">>,
+ [{secure, true}],
+ <<"Customer=WILE_E_COYOTE; Version=1; Secure">>},
+ {<<"Customer">>, <<"WILE_E_COYOTE">>,
+ [{secure, false}, {http_only, false}],
+ <<"Customer=WILE_E_COYOTE; Version=1">>},
+ {<<"Customer">>, <<"WILE_E_COYOTE">>,
[{path, <<"/acme">>}, {badoption, <<"negatory">>}],
<<"Customer=WILE_E_COYOTE; Version=1; Path=/acme">>}
],