node.js - Content-Length header 是压缩字节还是未压缩字节的字节大小?

标签 node.js http webserver

我正在 node.js 中实现静态文件服务。假设我要发送一个名为 party-time.txt 的文件,它是:

100 字节未压缩

gzipped 70 字节

如果我发送 gzipped 文件,Content-Length header 应该是 100 还是 70

最佳答案

请看specification .它明确指出:

Applications SHOULD use this field to indicate the transfer-length of the message-body, unless this is prohibited by the rules in section 4.4.

深入挖掘:

The message-body (if any) of an HTTP message is used to carry the
entity-body associated with the request or response. The message-body differs from the entity-body only when a transfer-coding has been
applied, as indicated by the Transfer-Encoding header field (...)

所以,Content-length 就是压缩包的大小。

关于node.js - Content-Length header 是压缩字节还是未压缩字节的字节大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32145031/

相关文章:

node.js 需要 ("fs") 给出空对象

node.js - 如何使用数组在FilterExpression中使用 “IN”语句 - dynamodb

node.js - 如何使用 Intl 来 brew install node.js?

java - 关于可以支持用Java编写的Web服务的轻量级开源Web服务器的建议

带有集成 Web 服务器的 PHP IDE

node.js - 在 express.js 中验证用户数据后如何上传图像

http - 当我尝试使用 HTTP 协议(protocol)发出请求时,为什么会收到 Bad Request 响应?

javascript - 通过 http 发送非常大的播放列表数据的最有效方法是什么?

php - Angularjs获取post查询结果

webserver - Varnish 配置文件在哪里?