gpt4 book ai didi

php - Apache RewriteRule 丢弃 SetInputFilter DEFLATE 配置指令

转载 作者:行者123 更新时间:2023-12-04 20:20:36 27 4
gpt4 key购买 nike

我有以下(简化的)文件夹/文件结构:

/.htaccess
/test.php
/api/web/index.php

以及 apache 配置中的以下指令:
<IfModule mod_deflate.c>
<IfModule mod_filter.c>
SetInputFilter DEFLATE
</IfModule>
</IfModule>

我正在发送一个带有 gzipped 正文的 POST 请求,并带有适当的 header :
POST /test.php HTTP/1.1
Host: 192.168.1.248
Authorization: Bearer ed717c077e4bf81201196011adb457731b24e19d
Content-Type: application/json
Content-Encoding: gzip

我对 有以下配置.htaccess 文件:
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^api/(.*) api/web/index.php/$1 [NC,L]

问题是,如果我发帖到 /test.php ,一切都按预期工作, body 放气了,我可以正确访问解压缩的内容。

但是,如果我发布到被重定向的内容( /api//api/v1/project), index.php脚本没有解压正文。

我想一定和 RewriteRule有关忽略 SetInputFilter 的指令指令,但是,我怎样才能避免这种情况呢?

我尝试添加 SetInputFilter直接在 .htaccess 中指令而不解决问题(可能是它不在正确的位置?)。

你知道我该如何解决这个问题吗?

最佳答案

确实,有问题。我做深入调查的第一件事是记录相关模块的痕迹( rewritefilterdeflate )。

mod_rewrite 日志 还可以,那里没有什么可疑的。为了确保一切正常,我查看了它的最新版本 source code .再一次,没有关于编码/解码的可疑之处(更一般地说,也没有 http 请求/响应 header )。

所以我开始认为问题可能来自 filterdeflate模块,即使它也可能来自其他地方。为了确认/确认我的想法,我查看了这些模块日志。很快,我就看到了两个测试用例之间的区别:有或没有 mod_rewrite涉及。

不涉及 mod_rewrite

mod_deflate.c(1421): [client 127.0.0.1:53000] AH01393: Zlib: Inflated 35 to 41 : URL /test.php
mod_filter.c(188): [client 127.0.0.1:53000] Content-Type condition for 'deflate' matched

我把这个作为引用来比较下面的下一个案例

涉及 mod_rewrite
mod_filter.c(188): [client 127.0.0.1:53002] Content-Type condition for 'deflate' matched

有趣的。实际上,它看起来像 mod_deflate是问题所在。我怀疑它的行为是 之后 正确的时刻。这就是为什么你在这种情况下看不到它的原因。

解决方案

到现在为止还挺好。所以呢 ?嗯,快速搜索一下 Apache 的已知 bug 列表,关键字 mod_deflate too late ,偶然给了我 what I was searching for .这张票叫 mod_deflate adjusts the headers "too late" , 声明如下:

When mod_deflate is used to inflate, it must adjust the request headers (e.g. it needs to remove the "Content-Length" header and adjust the "Content-Encoding" header).

Currently mod_deflate adjusts the headers when the request body is read. But this is too late. For example, if a content generator module needs to look at the request headers before reading the request body, the content generator module "sees" the old (unmodified) headers.

mod_deflate should adjust the headers in an early stage, for example in a fixup hook (ap_hook_fixups).



Eureka !这正是我们面临的问题。现在,好消息是有一个补丁可以解决这个问题。坏消息:它尚未在可用版本中进行审查/接受/合并。

您可以选择 :
  • 应用此补丁并重新编译您的服务器。它应该起作用,因为一切都是有意义的。 但是,要小心 ...这可能会引入其他错误/漏洞(有时会出现这种情况,即使在审查/接受时也是如此)
  • 等待它包含在可用版本中(可能需要很长时间,考虑到票日期)。到那时,使用你的自定义放气和 php。

  • 更新

    刚试过打补丁重新编译 mod_deflate .看起来它在正确的轨道上:它吃 Content-Encoding标题。无论如何, Content-Length还在那里。结果:还没有解压。所以,还有一些事情要做和适应,但问题肯定出在那个领域。

    更新 2(工作)

    我终于成功了。这是我应用于 Apache 的补丁 ( httpd version 2.4.34):
    diff --git a/modules/filters/mod_deflate.c b/modules/filters/mod_deflate.c
    index 1428460..cc8c0cb 100644
    --- a/modules/filters/mod_deflate.c
    +++ b/modules/filters/mod_deflate.c
    @@ -1099,10 +1099,10 @@ static apr_status_t deflate_in_filter(ap_filter_t *f,

    if (!ctx) {
    /* only work on main request/no subrequests */
    - if (!ap_is_initial_req(r)) {
    + /*if (!ap_is_initial_req(r)) {
    ap_remove_input_filter(f);
    return ap_get_brigade(f->next, bb, mode, block, readbytes);
    - }
    + }*/

    /* We can't operate on Content-Ranges */
    if (apr_table_get(r->headers_in, "Content-Range") != NULL) {

    其实我做了 mod_deflate也处理子请求。我不确定它不会破坏其他一些模块,但它适用于您的用例(它更像是一个概念证明)。无论如何,我在上面提到的票上提出了我的补丁。这是结果的屏幕截图:

    enter image description here

    关于php - Apache RewriteRule 丢弃 SetInputFilter DEFLATE 配置指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44951644/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com