大猩猩会话-如何根据请求自动更新Cookie过期? [英] Gorilla Sessions - How to Automatically Update Cookie Expiration on Request?

查看:103
本文介绍了大猩猩会话-如何根据请求自动更新Cookie过期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道许多其他语言和网络框架会在每次通过后端访问会话(或类似操作)时自动将cookie的过期时间更新为会话超时。我不相信Gorilla会提供此实用程序。



更新cookie过期的最佳做法是什么,尤其是与大猩猩/围棋有关的最佳做法?

解决方案

如果设置cookie的Max-Age参数,则无需设置Expiry,除非需要支持旧的浏览器



仅使用Max-Age意味着您不需要在每个请求上都进行更新。



设置规范: http://tools.ietf。 org / html / rfc6265#section-4.1.2


I know many other languages and web frameworks will automatically update a cookie's expiration time to the session timeout every time a session is accessed via the backend (or some action like that). I don't believe Gorilla provides this utility.

I am consider just writing some request middleware that, if it detects a valid session, will extend the cookie lifetime but I am wondering if there is a better method of doing this.

What are the best practices for updating cookie expiration, especially as they pertain to Gorilla/Go?

解决方案

If you set the Max-Age parameter of the cookie, you don't need to set Expiry as well, unless you need to support old browsers that don't understand Max-Age.

Using only Max-Age means you don't need to update it on every request.

Set the spec: http://tools.ietf.org/html/rfc6265#section-4.1.2

这篇关于大猩猩会话-如何根据请求自动更新Cookie过期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆