使用 gzip 编码数据时应该发送多长的内容?

发布于 2024-07-23 08:24:48 字数 96 浏览 6 评论 0原文

我正在编写一个小型网络服务器,并且想发送压缩数据。

在 http 标头的 Content-Length 字段中,我应该设置压缩数据的长度还是未压缩数据的长度?

I am writing a small web server and would like to send gzipped data.

In the http header for the Content-Length field do I set the length of the compressed data or the length of the uncompressed data?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

兔小萌 2024-07-30 08:24:48

压缩的。

Compressed.

顾忌 2024-07-30 08:24:48

您必须指定发送的实际数据的大小,在您的情况下这将是压缩数据的大小。

但是,需要记住一点 - 如果数据以分块形式发送(“Transfer-Encoding:分块”),那么您根本不允许发送 Content-Length 标头。 分块决定了如何读取字节。 Content-Length 标头会破坏客户端正确读取块的能力。

You have to specify the size of the actual data being sent, which in your case would be the compressed data size.

However, something to keep in mind - if the data is being sent as chunked ("Transfer-Encoding: chunked"), then you are NOT allowed to send a Content-Length header at all. The chunking dictates how the bytes are read. A Content-Length header would break the client's abilty to read the chunks correctly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文