将gzip压缩的响应发送给未指定Accept-Encoding:gzip的客户端是否是一个bug? [英] is it a bug to send response gzip-compressed to clients that doesn't specify Accept-Encoding: gzip?
问题描述
如果将gzip压缩的内容发送给未指定Accept-Encoding: gzip
的客户端,这是否是服务器中的错误?是否违反了http规范?还是合法的?
is it a bug in the server if it sends content gzip-compressed to clients that did not specify Accept-Encoding: gzip
? is it breaking the http specs? or is it legal?
我很好奇,因为 https://www.amazon.com 总是发送以gzip压缩的内容,无论是否接受Accept-Encoding标头,都可以通过以下简单测试来确认:
i'm curious because https://www.amazon.com always sends content gzip-compressed, regardless of the Accept-Encoding header, as a simple test to confirm:
$ 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==
- curl抱怨说它在这里接收二进制数据,因为它不是用HTML响应的,而是gzip压缩的html,它是二进制数据.要真正看到html,请添加
--compressed
参数,该参数告诉curl添加标头Accept-Encoding: gzip, deflate
并自动解压缩响应. - curl complains that it's recieving binary data here because it's not responding with HTML, but gzip-compressed html, which is binary data. to actually see the html, add the
--compressed
argument, which tells curl to add the headerAccept-Encoding: gzip, deflate
and automatically decompress the response.
推荐答案
没有Accept-Encoding头字段的请求意味着用户代理对内容编码没有任何偏好.尽管这允许服务器在响应中使用任何内容编码,但这并不意味着用户代理将能够正确处理所有编码.
A request without an Accept-Encoding header field implies that the user agent has no preferences regarding content-codings. Although this allows the server to use any content-coding in a response, it does not imply that the user agent will be able to correctly process all encodings.
- https://greenbytes .de/tech/webdav/rfc7231.html#rfc.section.5.3.4.p.4
这篇关于将gzip压缩的响应发送给未指定Accept-Encoding:gzip的客户端是否是一个bug?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!