HTTPでエンコーディングしていないコンテンツを要求

Chrome の場合、 リクエストヘッダーの Accept-encodingaccept-encoding: gzip,deflate,sdch というようになっていて、サーバには圧縮コンテンツを要求している

深淵な理由により、Web サーバにエンコーディングしていないコンテンツを要求したい場合は、 "Accept-Encoding" の値を "identity" にするか、ブランクにすると良い。

RFC 2616 : Hypertext Transfer Protocol — HTTP/1.1 を確認すると

3.5 Content Codings

identity The default (identity) encoding; the use of no transformation whatsoever. This content-coding is used only in the Accept- Encoding header, and SHOULD NOT be used in the Content-Encoding header.

14.3 Accept-Encoding

If the Accept-Encoding field-value is empty, then only the “identity” encoding is acceptable.

というように書かれている。

accept-encoding: gzip,deflate,sdch の場合

$ curl "https://m.facebook.com/" \
 -H "accept-encoding: gzip,deflate,sdch" \
 -H "accept-language: en-US,en;q=0.8,ja;q=0.6" \
 -H "user-agent: Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X; en-us) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53" \
 -H "accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" \
 -D - -o /dev/null

Cache-Control: private, no-cache, no-store, must-revalidate
Content-Type: text/html; charset=utf-8
Expires: Sat, 01 Jan 2000 00:00:00 GMT
P3P: CP="Facebook does not have a P3P policy. Learn why here: http://fb.me/p3p"
Pragma: no-cache
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-XSS-Protection: 0
Set-Cookie: datr=2dAIUwYSMmGO55NvD0wCj3oo; expires=Mon, 22-Feb-2016 16:31:21 GMT; path=/; domain=.facebook.com; httponly
Set-Cookie: m_ts=1393086681; path=/; domain=.facebook.com; httponly
Set-Cookie: reg_ext_ref=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=.facebook.com
Set-Cookie: reg_fb_gate=https%3A%2F%2Fm.facebook.com%2F; path=/; domain=.facebook.com
Set-Cookie: reg_fb_ref=https%3A%2F%2Fm.facebook.com%2F; path=/; domain=.facebook.com
Content-Encoding: gzip
X-FB-Debug: eUo1tAzOcNLLpFK/2QBwyAwHlwKLmyhcfPgzTTTmgVo=
Date: Sat, 22 Feb 2014 16:31:21 GMT
Transfer-Encoding: chunked
Connection: keep-alive

100  4770    0  4770    0     0   8613      0 --:--:-- --:--:-- --:--:--  9190

Content-Encoding: gzip と gzip 圧縮して転送されている

accept-encoding: identity の場合

$ curl "http://en.m.wikipedia.org/wiki/HTTP_compression" \
 -H "accept-encoding: identity" \
 -H "user-agent: Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X; en-us) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53" \
 -H "accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" \
 -D - -o /dev/null

Server: Apache
X-Powered-By: PHP/5.3.10-1ubuntu3.9+wmf1
X-Content-Type-Options: nosniff
Content-language: en
X-WAP: no
Vary: Accept-Encoding,X-WAP,Cookie,X-CS,X-Subdomain,X-Forwarded-By
X-Vary-Options: Accept-Encoding;list-contains=gzip,X-WAP,Cookie;string-contains=enwikiToken;string-contains=enwikiLoggedOut;string-contains=forceHTTPS;string-contains=enwikiSession;string-contains=centralauth_Token;string-contains=centralauth_Session;string-contains=centralauth_LoggedOut;string-contains=mf_useformat;string-contains=stopMobileRedirect;string-contains=optin;string-contains=disableImages,X-CS,X-Subdomain,X-Forwarded-By
Last-Modified: Sat, 15 Feb 2014 16:01:52 GMT
Content-Type: text/html; charset=UTF-8
X-Varnish: 1438789418 1424689684, 1639350314 1608109908, 2332835751 2330347883
Via: 1.1 varnish, 1.1 varnish, 1.1 varnish
Transfer-Encoding: chunked
Date: Sat, 22 Feb 2014 16:32:25 GMT
Age: 161849
Connection: keep-alive
X-Cache: cp1046 hit (2), cp4011 hit (3), cp4012 frontend hit (3)
Cache-Control: s-maxage=300, must-revalidate, max-age=0

100 45577    0 45577    0     0  96064      0 --:--:-- --:--:-- --:--:--  128k

レスポンスヘッダーに Content-Encoding は含まれていない。

accept-encoding がない場合

accept-encoding フィールドがない場合

RFC 2616 : Hypertext Transfer Protocol — HTTP/1.1 では次のように書かれている

14.3 Accept-Encoding

If no Accept-Encoding field is present in a request, the server MAY assume that the client will accept any content coding. In this case, if “identity” is one of the available content-codings, then the server SHOULD use the “identity” content-coding, unless it has additional information that a different content-coding is meaningful to the client.

どのエンコーディングを利用するかはサーバに委ねられている。
2010年頃の Google の発表によると、Google(のどのサービス?) は Accept-Encoding ヘッダーがかけている場合、UA を元に圧縮に対応指定そうなブラウザーには gzip 圧縮したコンテンツを返していると書かれている。

Velocity: Forcing Gzip Compression | High Performance Web Sites

http://www.stevesouders.com/blog/2010/07/12/velocity-forcing-gzip-compression/

数年経った現在、UA は Chrome のまま Accept-Encoding  だけをはずして Google.com に検索すると、圧縮されていないコンテンツがかってきたので、今の仕様は不明。

関連するかもしれないリンク

Leave a comment