当我在 Catalyst 中使用 Cache-Control 标头时,如何不发送 cookie?
我通过 Session
、Session::Store::DBIC
和 Session::State::Cookie
在 Catalyst 应用程序中使用会话。
我有一些控制器和方法使用 Cache-Control: public
标头发送数据,因此 Set-Cookie:
标头不 带着这些响应出去(否则,它会被缓存并发送到其他客户端,从而导致可能的安全问题)。 我还没有找到一个好的方法来完成这个任务。
如何告诉 Session
或 Session::State::Cookie
不要发送 cookie 来响应给定的请求?
I'm using sessions in my Catalyst app via Session
, Session::Store::DBIC
, and Session::State::Cookie
.
I have a few controllers and methods that send out data with a Cache-Control: public
header, so its essential that the Set-Cookie:
header not go out with those responses (otherwise, it'd be cached and sent to other clients, leading to possible security issues). I haven't found a good way to accomplish this.
How can I tell Session
or Session::State::Cookie
to not send a cookie in response to a given request?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
执行一些 RTFS,
Session.pm
覆盖 Catalyst 的finalize_headers
方法并通过相当深的调用链在那里设置 cookie:
似乎没有任何方法可以将链中的任何内容标记为
停止。 唯一的检查是 Cookie.pm 中的一个方法,称为
cookie_is_rejecting
它只是将配置的 cookie 路径与请求路径。
所以,看起来最好的方法是将我自己的覆盖添加到
update_session_cookie
或cookie_is_rejecting
。 我想我会使用
cookie_is_rejecting
。这是我最终使用的代码。 请注意,这相当笨拙,但它有效......
Doing a little RTFS,
Session.pm
overrides Catalyst'sfinalize_headers
method and sets the cookie there, through a rather deep call chain:
There does not appear to be any way to flag anything in the chain to
stop. The only check is a method in
Cookie.pm
calledcookie_is_rejecting
which just compares the configured cookie path tothe request path.
So, it looks like the best way to do this is to add my own override to
either
update_session_cookie
orcookie_is_rejecting
. I think I'lluse
cookie_is_rejecting
.Here is the code I finally used. Note that this is rather klugy, but it works...
这种方式似乎有点不寻常,但我想我明白你在做什么。
如果我没记错的话,Cookie 状态模块只是在响应对象中设置 cookie:
我不认为那里有什么魔力,它只是将其设置为创建或延长会话时间。 如果您想确保不发送 cookie。 清除根端的
$c->response->cookies
,你应该可以开始了。杰克
It seems a bit unusual to approach it this way but I think I get what you are doing.
If I recall correctly, the Cookie State module simply sets the cookie in the response object:
I don't think there's any magic there, and it only sets it to create or extend the session time. If you want to ensure that no cookies are sent. Clear out
$c->response->cookies
in Root end and you should be good to go.JayK