我构建了一个用于压缩 HTTP 输出的模块。阅读spec ,我在以下几件事上没有发现明显的区别:
接受编码:
是否应将其视为与 Accept-Encoding: *
相同,还是视为不存在 header ?
或者如果我不支持 gzip,但我得到这样的 header 怎么办:
接受编码:gzip
我应该返回 406 错误还是仅返回未编码的数据?
编辑:
我已经阅读了该规范几次。它提到了我的第一个案例,但它没有定义服务器的行为应该是什么。
我应该将这种情况视为 header 不存在吗?或者我应该返回 406 错误,因为无法对给定字段值的内容进行编码(“”不是有效的编码)。
最佳答案
所有内容都写在Spec: 14.3 Accept-Encoding中:
The special "*" symbol in an Accept-Encoding field matches any available content-coding not explicitly listed in the header field.
If an Accept-Encoding field is present in a request, and if the server cannot send a response which is acceptable according to the Accept-Encoding header, then the server SHOULD send an error response with the 406 (Not Acceptable) status code.
编辑:
If the Accept-Encoding field-value is empty, then only the "identity" encoding is acceptable.
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.
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.
关于encoding - HTTP Accept-Encoding 并发送未编码的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6687896/