gzip压缩分块编码响应? [英] gzip compression of chunked encoding response?

查看:124
本文介绍了gzip压缩分块编码响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让我的网络服务器正确地gzip一个块响应的http响应。

I'm trying to get my webserver to correctly gzip an http response that is chunk encoding.

我对非gzip响应的理解是它看起来像这个:

my understanding of the non-gzip response is that it looks like this:

<the response headers>

然后对于每个块,

<chunk length in hex>\r\n<chunk>\r\n

最后是一个零长度的块:

and finally, a zero length chunk:

0\r\n\r\n

我试图让gzip压缩工作,我可以使用一些帮助计算实际上应该返回什么。此文档暗示整个响应应该被gzip压缩,而不是gzipping每个块:

I've tried to get gzip compression working and I could use some help figuring out what should actually be returned. This documentation implies that the entire response should be gzipped, as opposed to gzipping each chunk:

HTTP servers sometimes use compression (gzip) or deflate methods to optimize transmission.
Chunked transfer encoding can be used to delimit parts of the compressed object.
In this case the chunks are not individually compressed. Instead, the complete payload 
is compressed and the output of the compression process is chunk encoded.

我试图gzip整个事情并返回响应,即使没有分块,它也不起作用。我尝试将Content-Encoding标头设置为gzip。有人可以解释必须对上述方案进行哪些更改才能支持gzipping的大块?谢谢。

I tried to gzip the entire thing and return the response even without chunked, and it didn't work. I tried setting the Content-Encoding header to "gzip". Can someone explain what changes must be made to the above scheme to support gzipping of chunks? Thanks.

推荐答案

你gzip内容,然后才应用分块编码:

You gzip the content, and only then apply the chunked encoding:

由于chunked是HTTP / 1.1接收者需要理解的唯一传输编码,因此它在分隔持久连接上的消息时起着至关重要的作用。每当传输编码应用于有效负载体时在请求中,应用的最终传输编码必须是分块。如果传输编码应用于响应有效载荷主体,则应用的最终传输编码必须分块或者必须通过关闭终止消息当使用分块传输编码时,它必须是用于形成消息体的最后一个传输编码。分块传输编码绝不能在消息体中多次应用。

"Since "chunked" is the only transfer-coding required to be understood by HTTP/1.1 recipients, it plays a crucial role in delimiting messages on a persistent connection. Whenever a transfer-coding is applied to a payload body in a request, the final transfer-coding applied MUST be "chunked". If a transfer-coding is applied to a response payload body, then either the final transfer-coding applied MUST be "chunked" or the message MUST be terminated by closing the connection. When the "chunked" transfer-coding is used, it MUST be the last transfer-coding applied to form the message-body. The "chunked" transfer-coding MUST NOT be applied more than once in a message-body."

HTTPbis第1部分,第6.2.1节

这篇关于gzip压缩分块编码响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆