如何在不重定向的情况下将 cookie 添加到 Seaside 响应中?
我正在 Seaside 制作一个小型网络应用程序。 我有一个登录组件,在用户登录后,我想在下一个组件呈现自身时发送 cookie。 有没有办法获取处理响应的对象,以便我可以向它将输出的标头添加一些内容?
我试图避免使用 WASession>>redirectWithCookies 因为仅因为我想设置 cookie 才进行重定向似乎很麻烦。
是否已经存在另一种方法来添加将在下一个响应中发出的 cookie?
I'm making a small web application in Seaside. I have a login component, and after the user logs in I want to send along a cookie when the next component renders itself. Is there a way to get at the object handling the response so I can add something to the headers it will output?
I'm trying to avoid using WASession>>redirectWithCookies since it seems pretty kludgey to redirect only because I want to set a cookie.
Is there another way that already exist to add a cookie that will go out on the next response?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
目前没有内置方法可以在请求处理的操作/回调阶段添加 cookie。 这很可能是一个缺陷,并在本期中指出:http:// /code.google.com/p/seaside/issues/detail?id=48
目前预计 Seaside 2.9 会修复此问题,但我不知道它是否会向后移植到 2.8。
请记住,操作和渲染阶段之间已经存在(默认情况下)重定向,以防止刷新重新触发回调,因此从总体上看,在这种情况下,再进行一次重定向并不是太糟糕了。
如果您仍想进一步挖掘,请查看 WARenderContinuation>>handleRequest:。 这就是触发回调处理并开始重定向或渲染阶段的地方。
编辑添加:
该问题现已修复,(在最新的开发代码中)您现在可以随时将 cookie 正确添加到当前响应中。 只需访问当前请求上下文中的响应对象并添加 cookie。 例如,您可能会执行以下操作:
这不太可能向后移植到 Seaside 2.8,因为它需要对响应的处理方式进行相当大的转变。
There is currently no built-in way to add cookies during the action/callback phase of request processing. This is most likely a defect and is noted in this issue: http://code.google.com/p/seaside/issues/detail?id=48
This is currently slated to be fixed for Seaside 2.9 but I don't know if it will even be backported to 2.8 or not.
Keep in mind that there is already (by default) a redirection between the action and rendering phases to prevent a Refresh from re-triggering the callbacks, so in the grand scheme of things, one more redirect in this case isn't so bad.
If you still want to dig further, have a look at WARenderContinuation>>handleRequest:. That's where callback processing is triggered and the redirect or rendering phase begun.
Edited to add:
The issue has now been fixed and (in the latest development code) you can now properly add cookies to the current response at any time. Simply access the response object in the current request context and add the cookie. For example, you might do something like:
This is unlikely to be backported to Seaside 2.8 as it required a fairly major shift in the way responses are handled.
我刚刚深入研究过这个问题,答案似乎是否定的。 具体来说,无法从 WARenderCanvas 或其可以访问的任何内容获取响应(它保存在 WARenderingContext 上,而 WARenderingContext 保存在 WAHtmlStreamDocument 上,WAHtmlStreamDocument 保存在响应的流上,但不是响应本身) 。 我认为给予上下文访问当前响应的权限是合理的,正是为了能够在其上设置标头,但是您问是否已经有办法了,所以:没有。
也就是说,Seaside 做了很多额外的重定向,而且似乎对用户体验没有太大影响,所以也许要做的就是停止担心它看起来很笨拙,并遵循已经存在的 API 流程那里 :)
I've just looked into this in depth, and the answer seems to be no. Specifically, there's no way to get at the response from the WARenderCanvas or anything it can access (it holds onto the WARenderingContext, which holds onto the WAHtmlStreamDocument, which holds onto the response's stream but not the response itself). I think it would be reasonable to give the context access to the current response, precisely to be able to set headers on it, but you asked if there was already a way, so: no.
That said, Seaside does a lot of extra redirecting, and it doesn't seem to have much impact on the user experience, so maybe the thing to do is to stop worrying about it seeming kludgey and go with the flow of the API that's already there :)