From e6a1f1a4f30bad94baad718c0d4b9945b5c2c903 Mon Sep 17 00:00:00 2001 From: Krzysztof Jurewicz Date: Tue, 21 Jul 2015 11:10:47 +0200 Subject: Fix handling of default values in cookie options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, an error would be raised when explicitly passing a default value for either “http_only” or “secure” option. --- src/cow_cookie.erl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/cow_cookie.erl b/src/cow_cookie.erl index 6db89be..4e36ec4 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">>, @@ -217,6 +219,12 @@ setcookie_test_() -> {<<"Customer">>, <<"WILE_E_COYOTE">>, [{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">>} -- cgit v1.2.3