cowboy icon indicating copy to clipboard operation
cowboy copied to clipboard

Issue deleting cookie

Open vboikotriller opened this issue 3 years ago • 2 comments

First I tried to set max_age to 0, as recommended in cowboy documentation:

Req1 = cowboy_req:set_resp_cookie(utils:to_binary(SessionCookieName), <<"deleted">>, Req0, #{max_age => 0}),

The cookie was not deleted by browser.

Then I tried to set the headers manually.

        Req1 = cowboy_req:reply(200, #{
            <<"content-type">> => <<"text/html">>,
            <<"set-cookie">> => <<"midsessionid=deleted; Version=1; Expires=Thu, 01-Jan-1970 00:00:01 GMT">>
        }, Body, Req0),

Cowboy raised the following error.

10:41:23.495 [error] CRASH REPORT Process <0.774.0> with 0 neighbours crashed with reason: no function clause matching cowboy_http:'-headers_to_list/1-lc$^0/1-0-'(<<"midsessionid=deleted; Version=1; Expires=Thu, 01-Jan-1970 00:00:01 GMT">>) line 1183

Then I renamed header to "Set-Cookie" and it worked.

But if I add Max-Age=0 the expiration date sets to current date, instead of requested year 1970. It looks like max_age approach could not work.

vboikotriller avatar May 08 '21 07:05 vboikotriller

What browser?

essen avatar May 08 '21 08:05 essen

Chrome

vboikotriller avatar May 11 '21 15:05 vboikotriller

I have tried the cookie example and added some code to delete the cookie the server sets. It works as intended. Please provide the full snippet next time because you likely made a mistake somewhere that lead to the set-cookie header not being in the response or similar. Also request/response headers help for these scenarios. Closing, thanks!

essen avatar Jan 08 '24 14:01 essen