Apache 不发送 304 响应(如果启用了 mod_deflate 和 AddOutputFilterByType) [英] Apache is not sending 304 response (if mod_deflate and AddOutputFilterByType is enabled)

查看:42
本文介绍了Apache 不发送 304 响应(如果启用了 mod_deflate 和 AddOutputFilterByType)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的 Apache httpd.conf 中添加了以下行:-

AddOutputFilterByType DEFLATE text/html text/css application/javascript application/x-javascript application/json

我有一个包含脚本的 html 文件 (test.html):-

问题是,每次加载test.html,test.js也加载了HTTP状态:200.

问题是:为什么不满足条件GET?

如果我在 httpd.conf 中注释掉AddOutputFilterByType"行,Apache 会发送 304.

如果我在httpd.conf中启用AddOutputFilterByType,请求头是:-

<前>主持人:优化用户代理:Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10 GTB5 (.NET CLR 3.5.30729) FirePHP/0.2.4接受: */*接受语言:en-us,en;q=0.5接受编码:gzip、deflate接受字符集:ISO-8859-1,utf-8;q=0.7,*;q=0.7保持活力:300连接:保持连接推荐人:http://optimize/Cookie:PHPSESSID=nbq6h0eeahkshkcbc6ctu2j2b4If-Modified-Since: 2009 年 5 月 19 日星期二 07:06:46 GMTIf-None-Match: "2000000000717f-2c25a-46a3e8dcc2ad8"-gzip缓存控制:max-age=0

响应头是:-

<前>日期:2009 年 5 月 22 日星期五 07:03:40 GMT服务器:Apache/2.2.9 (Win32) PHP/5.2.6最后修改时间:2009 年 5 月 19 日,星期二 07:06:46 GMTEtag:2000000000717f-2c25a-46a3e8dcc2ad8"-gzip接受范围:字节变化:接受编码内容编码:gzip内容长度:52583保持活动:超时=5,最大=98连接:保持活动内容类型:应用程序/javascript

更新:我注意到,如果我禁用 ETag,它可以正常工作.我的意思是它发送 304.

FileETag 无

但我真的想保持 ETag 原样(我知道存在 inode 披露问题).

解决方案

这是 Apache 中的一个已知错误.请参阅 Apache 错误 #45023Apache 304 etags 和 mod_deflate 摘要.

从 svn 重建将解决该问题.解决方案是恢复将-gzip"附加到 etag 的更改.但是,存在相关的 HTTP 合规性问题.

如果您无法重建 Apache,错误报告中有一个建议的运行时配置解决方法:

 RequestHeader 编辑 "If-None-Match" "^\"(.*)-gzip\"$" "\"$1\""标题编辑 "ETag" "^\"(.*[^g][^z][^i][^p])\"$" "\"$1-gzip\""

I have added the following line in my Apache httpd.conf: -

AddOutputFilterByType DEFLATE text/html text/css application/javascript application/x-javascript application/json

I have a html file (test.html) with a script inclusion: -

<script type="text/javascript" src="/test.js"></script>

The problem is, every time I load test.html, test.js is also loaded with HTTP status: 200.

The question is: Why conditional GET is not satisfied?

If I comment out the "AddOutputFilterByType" line in httpd.conf, Apache sends 304.

If I enable AddOutputFilterByType in httpd.conf, the request header is: -

Host: optimize
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10 GTB5 (.NET CLR 3.5.30729) FirePHP/0.2.4
Accept: */*
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://optimize/
Cookie: PHPSESSID=nbq6h0eeahkshkcbc6ctu2j2b4
If-Modified-Since: Tue, 19 May 2009 07:06:46 GMT
If-None-Match: "2000000000717f-2c25a-46a3e8dcc2ad8"-gzip
Cache-Control: max-age=0

And the response header is: -

Date: Fri, 22 May 2009 07:03:40 GMT
Server: Apache/2.2.9 (Win32) PHP/5.2.6
Last-Modified: Tue, 19 May 2009 07:06:46 GMT
Etag: "2000000000717f-2c25a-46a3e8dcc2ad8"-gzip
Accept-Ranges: bytes
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 52583
Keep-Alive: timeout=5, max=98
Connection: Keep-Alive
Content-Type: application/javascript

UPDATE: I have noticed, if I am disabling ETag, it works properly. I mean it sends 304.

FileETag None

But I really want to keep ETag as it is (I know that there is a inode disclosure issue).

解决方案

This is a known bug in Apache. See Apache bug #45023, and summary of Apache 304 etags and mod_deflate.

Rebuilding from svn will fix the issue. The resolution was to revert the change that appended "-gzip" to the etag. However, there are associated HTTP compliance problems.

If you can't rebuild Apache, there is a suggested runtime configuration workaround in the bug report:

 RequestHeader  edit "If-None-Match" "^\"(.*)-gzip\"$" "\"$1\""
 Header  edit "ETag" "^\"(.*[^g][^z][^i][^p])\"$" "\"$1-gzip\""

这篇关于Apache 不发送 304 响应(如果启用了 mod_deflate 和 AddOutputFilterByType)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆