时间:2021-07-01 10:21:17 帮助过:18人阅读
curl -v -I -H "Accept-Encoding: gzip,deflate" http://www.ihezhu.com/
* About to connect() to www.ihezhu.com port 80 (#0) * Trying 210.51.54.180... connected > HEAD / HTTP/1.1 > User-Agent: curl/7.22.0 (i686-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3 > Host: www.ihezhu.com > Accept: */* > Accept-Encoding: gzip,deflate > < HTTP/1.1 200 OK HTTP/1.1 200 OK < Server: nginx Server: nginx < Date: Fri, 18 Jan 2013 10:13:19 GMT Date: Fri, 18 Jan 2013 10:13:19 GMT < Content-Type: text/html; charset=utf-8 Content-Type: text/html; charset=utf-8 < Connection: keep-alive Connection: keep-alive < Vary: Accept-Encoding Vary: Accept-Encoding < Set-Cookie: PHPSESSID=i6nkkd79n7uenikq2727u8rln6; path=/ Set-Cookie: PHPSESSID=i6nkkd79n7uenikq2727u8rln6; path=/ < Expires: Thu, 19 Nov 1981 08:52:00 GMT Expires: Thu, 19 Nov 1981 08:52:00 GMT < Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 < Pragma: no-cache Pragma: no-cache < Content-Encoding: gzip Content-Encoding: gzip * no chunk, no close, no size. Assume close to signal end < * Closing connection #0
但直接浏览器却没有看到输出Content-Encoding 大概怎么回事?
谢谢
====update
原因暂时还不明, 说下我做的测试
用fiddler访问, 不输出
用fiddler按照curl构造参数, 不输出
用chrome插件模拟curl请求, 不输出
在本机模拟了服务器配置一致的环境(php.ini, fastcgi, nginx.conf以及站点配置), 可以输出
现在准备在curl中模拟browser的请求, 看看怎样
环境 nginx + php-fpm
curl -v -I -H "Accept-Encoding: gzip,deflate" http://www.ihezhu.com/
* About to connect() to www.ihezhu.com port 80 (#0) * Trying 210.51.54.180... connected > HEAD / HTTP/1.1 > User-Agent: curl/7.22.0 (i686-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3 > Host: www.ihezhu.com > Accept: */* > Accept-Encoding: gzip,deflate > < HTTP/1.1 200 OK HTTP/1.1 200 OK < Server: nginx Server: nginx < Date: Fri, 18 Jan 2013 10:13:19 GMT Date: Fri, 18 Jan 2013 10:13:19 GMT < Content-Type: text/html; charset=utf-8 Content-Type: text/html; charset=utf-8 < Connection: keep-alive Connection: keep-alive < Vary: Accept-Encoding Vary: Accept-Encoding < Set-Cookie: PHPSESSID=i6nkkd79n7uenikq2727u8rln6; path=/ Set-Cookie: PHPSESSID=i6nkkd79n7uenikq2727u8rln6; path=/ < Expires: Thu, 19 Nov 1981 08:52:00 GMT Expires: Thu, 19 Nov 1981 08:52:00 GMT < Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 < Pragma: no-cache Pragma: no-cache < Content-Encoding: gzip Content-Encoding: gzip * no chunk, no close, no size. Assume close to signal end < * Closing connection #0
但直接浏览器却没有看到输出Content-Encoding 大概怎么回事?
谢谢
====update
原因暂时还不明, 说下我做的测试
用fiddler访问, 不输出
用fiddler按照curl构造参数, 不输出
用chrome插件模拟curl请求, 不输出
在本机模拟了服务器配置一致的环境(php.ini, fastcgi, nginx.conf以及站点配置), 可以输出
现在准备在curl中模拟browser的请求, 看看怎样
建议你用wireshark抓包看看,可能只是chrome没显示这个出来。
感觉chrome的开发者工具不那么靠谱,比如显示出了 Transfer-Encoding: chunked,但是显示出来的却找不是原始的response(不是chunked的格式)。
这个问题很有意思, 我猜是你在curl的时候, request headers提供的不足, 所以没有被CDN cache到.
但是在浏览器的情况下, request headers很完整, 所以CDN就起作用了, 既然CDN服务器节点靠近你自己的网络, 那么就不用压缩了, 直接返回给你明文, 跳过gzip节省浏览器解压时间, 加速网页响应.
我这么猜是因为response header里面有个Vary, 查了一下Vary的功能和CDN有关