How to get and reuse expiration date from the cookie?

Hello, when I create cookie with Name, Value and Expires filled in (via http.SetCookie) and then use func (*Request) Cookie, I’ll get just the Name and the Value of the cookie. How can I get Expiration date and time of that cookie? My browser show me the expiration date, but when I suck the cookie via func (*Request) Cookie to variable and then SetCookie again, it will set the cookie just for the session. Thanks.more info to the cookie? Thank you very much.

Regrettably the cookie specification does not make that information available, so the net/http package cannot provide it.

https://tools.ietf.org/html/rfc6265#section-4.2

But when I set the cookie and with Expires field filled in I look to cookie in dev. tools in the browser, it shows me the expiration date. Where is this date stored then? I am really confused. Sorry for my little knowledge.

All that data is maintained on the client and not transmitted to the server.

you could try to read the cookie from javascript and send it back periodically to a web service (your server) with ajax.

Let’s turn the question around. If you could retrieve the expiration date from a cookie, what would you do with that information? Maybe there is some way to solve that problem instead.

2 Likes

yep, a very good question. maybe @benesva4 will explain what he want to do with that information.

Hi again. Sorry for not responding. There was not any reason for me or any problem I was trying to solve. I was simply playing with the cookies. I tried to make a cookie with fixed date of expiration and then update the Value of the cookie later without changing anything else.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.