如果将gzip压缩的内容发送给未指定Accept-Encoding: gzip
的客户端,这是否是服务器中的错误?是否违反了http规范?还是合法的?
我很好奇,因为https://www.amazon.com总是发送gzip压缩的内容,而不管Accept-Encoding标头如何,以此作为确认的简单测试:
$ curl https://www.amazon.com
Warning: Binary output can mess up your terminal. Use "--output -" to tell
Warning: curl to output it to your terminal anyway, or consider "--output
Warning: <FILE>" to save to a file.
$ curl https://www.amazon.com -I
HTTP/2 405
content-type: text/html; charset=UTF-8
server: Server
date: Sat, 03 Nov 2018 11:27:35 GMT
set-cookie: skin=noskin; path=/; domain=.amazon.com
strict-transport-security: max-age=47474747; includeSubDomains; preload
x-amz-id-1: 2M3HZHHA9J21D3MTHH4K
allow: POST, GET
vary: Accept-Encoding,User-Agent,X-Amazon-CDN-Cache
content-encoding: gzip
x-amz-rid: 2M3HZHHA9J21D3MTHH4K
x-frame-options: SAMEORIGIN
x-cache: Error from cloudfront
via: 1.1 1cc4305a3ce000ca199328864ca1c98e.cloudfront.net (CloudFront)
x-amz-cf-id: OKz61IdKmCBfC97pPg-zmDhQnJzK3THXL2iYwegU5EtDaRf6yjBGzw==
--compressed
参数,该参数告诉curl添加标题Accept-Encoding: gzip, deflate
并自动解压缩响应。答案 0 :(得分:1)
没有Accept-Encoding标头字段的请求意味着用户代理对内容编码没有任何偏好。尽管这允许服务器在响应中使用任何内容编码,但这并不意味着用户代理将能够正确处理所有编码。
-https://greenbytes.de/tech/webdav/rfc7231.html#rfc.section.5.3.4.p.4