为什么 grails URL 参数解码在服务器上与本地上的行为不同

发布于 2024-09-28 18:52:48 字数 526 浏览 11 评论 0原文

假设我的 grails URLMappings.groovy 中有以下条目:

"/actionName/param1"(controller:'myController', action:'myAction')

当我调用 param1 包含 + 作为特殊字符的 URL 时,该 URL 会被正确编码为 /actionName/my%2Bparam 例如,在我的本地环境和服务器环境中。

在我的本地环境中 - 也使用“prod”作为环境参数 - 这被正确解析为控制器中的 my+param 。然而,在我的“真实”生产环境(Amazon Web Service EC2 实例)中,URL 被解析为“my param”,这是错误的。

我不知道这可能是什么原因。两种环境都使用 TomCat,如上所述,我什至在本地环境中使用 prod 环境设置,因此开发和生产之间不可能有不同的配置。

有人知道我可以在哪里更深入地找出问题吗?

Let's say I have the following entry in my grails URLMappings.groovy:

"/actionName/param1"(controller:'myController', action:'myAction')

When I call an URL where param1 includes + as a special character, the URL is encoded correctly to /actionName/my%2Bparam for example, both in my local and in my server environment.

In my local environment - also using "prod" as the environment parameter - this is correctly resolved to my+param in the controller. However in my "real" production environment (Amazon Web Service EC2 instance), the URL is resolved to "my param" which is wrong.

I have no idea what the reason for this could be. Both environments use TomCat, and as stated above I'm even using the prod environment settings in my local environment so it can't be a differing configuration between development and production.

Does anybody have an idea where I could dig deeper to identify the problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

水晶透心 2024-10-05 18:52:48

EC2实例是否在Tomcat前面运行Apache?我之前遇到过参数被解码两次的问题,一次由 Apache 解码,另一次由 Tomcat 解码。根据记忆,我认为我调整了 Apache 中 ProxyPass 指令的配置来纠正它。

编辑:

我发现我在应用程序的源代码中留下了以下说明:)

Apache httpd.conf 添加

AllowEncodedSlashes On 
ProxyTimeout 3600

我们还升级了 apache 2.2.12+ 以修复 HEAD >使用启动 shell 脚本获取重写错误。

我还在 ProxyPass 指令中添加了“nocanon”选项,以停止 /etc/httpd/conf.d/cluster.conf 中 mod_proxy 的自动解码,

我认为我必须在服务器上执行此操作,因为您无法使用 GUI 修改它。我还有一条注释说这会导致它们查询字符串被编码。也许我必须在我的应用程序中添加一个额外的解码来处理这个问题(抱歉不能确定!)

Tomcat启动参数

-Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true
-Dorg.apache.catalina.connector.CoyoteAdapter.ALLOW_BACKSLASH=true

我认为这是为了让tomcat正确处理斜杠

欢呼

Lee

Is the EC2 instance running Apache in front of Tomcat? I've had issues before with params being decoded twice, once by Apache and then again by Tomcat. From memory, I think I adjusted the configuration of the ProxyPass directive in Apache to correct it.

EDIT:

I found the following instructions I'd left with the source code for my app :)

Apache httpd.conf additions

AllowEncodedSlashes On 
ProxyTimeout 3600

We also upgraded apache 2.2.12+ to fix HEAD > GET rewrite bug using a startup shell script.

I also added 'nocanon' option to ProxyPass directive to stop auto decoding by mod_proxy in /etc/httpd/conf.d/cluster.conf

I think I had to do this on the server as you can't modify this using the GUI. I also have a note that says it causes they query string to be encoded. Perhaps I had to add an extra decode in my app to handle this (sorry can't remember for sure!)

Tomcat startup parameters

-Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true
-Dorg.apache.catalina.connector.CoyoteAdapter.ALLOW_BACKSLASH=true

I think this was to get tomcat to handle slashes correctly

cheers

Lee

在巴黎塔顶看东京樱花 2024-10-05 18:52:48

这是 Groovy 1.3.4 或之前的几个构建版本中引入的已知错误。它已在当前版本 1.3.5 中修复。

这已正确解析为 my+param
在控制器中

否,预期的分辨率是“我的参数”(带空格)。
由于它适用于 Amazon 主机,因此您需要在本地将 Grails 升级到 1.3.5。

That's a known bug that has been introduced in Groovy 1.3.4 or few build versions before. It has been fixed in current version 1.3.5.

this is correctly resolved to my+param
in the controller

No, the expected resolution is "my param" (with a space).
As that works at the Amazon host, you'd upgrade Grails to 1.3.5, locally.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文