Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't get cookie expiration time in golang

Tags:

People also ask

How do you get cookie expiry time?

You can extend the life of a cookie beyond the current browser session by setting an expiration date and saving the expiry date within the cookie. This can be done by setting the 'expires' attribute to a date and time.

What happen if cookie expires max age is session?

Using cookies to do stuff Cookies without an Expires or Max-Age attribute are treated as session cookies, which means they are removed once the browser is closed. Setting a value on either Expires or Max-Age makes them permanent cookies, since they will exist until they hit their expiry date.

What is the default expire time of cookie?

If we does not set the expiry time of a cookie then when it will delete its self. The default Expiration Period for a Session is 20 minutes. The default Expiration Period for a Cookie is 30 minutes.

Which property is used to set expire date for cookie?

The Kind property of Expires is used to determine if the cookie is set to DateTimeKind.


I'm setting a new cookie

func f1(w http.ResponseWriter, r *http.Request) {
...
expire := time.Now().AddDate(0, 1, 0)
cookie := http.Cookie{"token", token, "/", "domain", expire, expire.Format(time.UnixDate), 86400, true, true, "token=" + token, []string{"token=" + token}}
http.SetCookie(w, &cookie)

Then i'm trying to get it

func f2(w http.ResponseWriter, r *http.Request) {
...
cookie, err := r.Cookie("token")
fmt.Println(cookie.Value)
fmt.Println(cookie.Expires)

Output

valid_token_string
0001-01-01 00:00:00 +0000 UTC

Value is the same i set, but Expires is empty. Why?