encoding - HTTP Accept-Encoding 并发送未编码的数据

标签 encoding http-headers

我构建了一个用于压缩 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.

What is "identity"

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/

相关文章:

c# - c# 用 Excel 打开的正确 CSV 编码是什么?

encoding - 相同类型的 base64 编码二进制数据是否具有相同的 header ?

php - PHP 联系表单的编码问题

python-3.x - python3的编码问题并单击包

http - cookie 中的 HMAC 有标准格式吗?

html - Windows Phone (IE 10) 无法播放 html5 视频(通过重定向)

node.js - 如何检测 NodeJS 中的文件编码?

azure - 删除服务器 :HTTPAPI/2. 0 无效请求 header

javascript - 我需要更详细地了解 cookie 的工作原理

flutter - 如何在 flutter web 中支持 HTTP header NetworkImage