向未指定Accept-Encoding:gzip的客户端发送gzip压缩的响应是一个错误吗?

时间:2018-11-03 11:31:44

标签: http

如果将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==
  • curl抱怨说它在这里接收二进制数据,因为它不是用HTML响应的,而是gzip压缩的html,它是二进制数据。要实际查看html,请添加--compressed参数,该参数告诉curl添加标题Accept-Encoding: gzip, deflate并自动解压缩响应。

1 个答案:

答案 0 :(得分:1)

  

没有Accept-Encoding标头字段的请求意味着用户代理对内容编码没有任何偏好。尽管这允许服务器在响应中使用任何内容编码,但这并不意味着用户代理将能够正确处理所有编码。

-https://greenbytes.de/tech/webdav/rfc7231.html#rfc.section.5.3.4.p.4