Grails 控制器中的重定向从 https 切换到 http。为什么?
我有一个 Grails 应用程序,其中一些页面只能通过 https 访问,一些页面只能通过 http 访问。使用前置过滤器可以轻松处理此问题。然而,当控制器在 https 页面上进行重定向时,用户最终会回到 http 并被过滤器再次定向到 https。
def update = {
...
redirect(action: "show", id: domainInstance.id)
}
在 Firebug 中,我得到:
POST ... localhost:8443 (the form submit to controller)
GET ... 302 ... localhost:8080 (the redirect to show in controller)
GET ... 301 ... localhost:8443 (the redirect back to https in filter)
如何让控制器重定向调用“记住”当前协议等?或者我做错了什么?
I have a Grails app with some pages only accessible over https and some over http. This is easily handled using a before filter. However when on an https page as soon as a controller does a redirect the user ends up back on http and is directed to https again by the filter.
def update = {
...
redirect(action: "show", id: domainInstance.id)
}
In Firebug I get:
POST ... localhost:8443 (the form submit to controller)
GET ... 302 ... localhost:8080 (the redirect to show in controller)
GET ... 301 ... localhost:8443 (the redirect back to https in filter)
How can I get the controller redirect call to "remember" the current protocol etc.? Or am I doing something else wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我通过使用后过滤器在需要时将响应中的“位置”标头转换为 https 来解决这个问题。默认的 CachingLinkGenerator 是使用 http 服务器 URL 构建的,并使用它来创建链接。所以似乎没有办法让它保持协议。我也找不到任何简单的方法来用我自己的扩展 LinkGenerator 替换它。
I sorted this out by using an after filter to convert the "Location" header in the response to https when needed. The default CachingLinkGenerator is constructed with the http server URL and uses this to create links. So there doesn't seem to be a way to get it to keep the protocol. I also couldn't see any easy way to replace it with my own extended LinkGenerator.
这是一个错误,似乎已在 2.0 版本中修复
It's a bug and appears to be fixed in version 2.0
我建议手动构建您的 URL 并
手动使用重定向,如下所示:
或
I would suggest constructing your URL manually and using redirect with that
Manually as in:
OR
我不确定您如何配置 grails 应用程序来运行 SSL。也许您已经在 tomcat 服务器连接器中透明地配置了它?
但是,在您的代码中您不应该关心 SSL 与否。也许这有帮助: http://www.juliesoft.com/ 2010/04/自动-httphttps-switching-with-grails/
I am not sure how you have configured your grails app to run SSL. Maybe you have configured it transparently in you tomcat server connector?
However, in your code you should not care about SSL or not. Maybe this helps: http://www.juliesoft.com/2010/04/automatic-httphttps-switching-with-grails/