Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
816 views
in Technique[技术] by (71.8m points)

http - Apache is not sending 304 response (if mod_deflate and AddOutputFilterByType is enabled)

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).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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""

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...