cowboy
cowboy copied to clipboard
Issue deleting cookie
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.
What browser?
Chrome
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!