securecookie:在使用sessions.NewFilesystemStore时,值太长了。

huangapple go评论69阅读模式
英文:

securecookie: the value is too long when using sessions.NewFilesystemStore

问题

我正在构建一个使用会话来存储用户数据的应用程序。为此,我使用了gorilla/sessions包。

我遇到的问题是随着应用程序的增长,我想要存储的用户数据越来越大。

在某个点上,当保存会话时,我遇到了这个错误:securecookie: the value is too long

这是我构建存储的方式:

sessions.NewFilesystemStore("", []byte("abcdef"))

我应该如何存储大型会话数据?

谢谢你的帮助。

英文:

I am building an app that uses sessions to store user data. For that I use the gorilla/sessions package.

The problem I encounter is that the user data I would like to store is getting bigger and bigger as the application grows.

At some point, i get that error while saving the session : securecookie: the value is too long

Here is how I build my storage :

sessions.NewFilesystemStore("", []byte("abcdef"))

How should I do to store large session data ?

Thank you for your help

答案1

得分: 2

这是来自浏览器 cookie 的4Kb 最大大小的遗产。当然,文件系统存储和可能的其他存储(不是 cookie 存储)可以容纳更大的会话数据。然而,由于某种原因,它的默认值是4Kb。要更改它,只需执行以下操作:

fs := sessions.NewFilesystemStore("", []byte("mysecretkey"))
fs.MaxLength(8192) // 现在会话的最大大小为8Kb
英文:

This is heritage from the 4Kb maximum size of a browser cookie. Of course the filesystem store and probably any other store that is not the cookie store can hold large(r) session data. However, it defaults to 4Kb for some reason. To change it just do something like:

fs := sessions.NewFilesystemStore("", []byte("mysecretkey"))
fs.MaxLength(8192) // 8Kb is now maximum size of the session

huangapple
  • 本文由 发表于 2022年10月14日 18:05:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/74067662.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定