简体   繁体   English

使用http压缩时的内容长度

[英]content-length when using http compression

The client is making a range request 0-1023 to the http server. 客户端正在向http服务器发出范围请求0-1023。 It prefers gzip compression with Accept-Encoding: gzip;q=1.0, identity; 它更喜欢使用Accept-Encoding进行gzip压缩:gzip; q = 1.0,identity; q=0.5, *;q=0 in the request. 请求中q = 0.5,*; q = 0。

What would be the content-length in the response header? 响应头中的内容长度是多少? Will it be 1024 or the size of the compressed data. 它是1024还是压缩数据的大小。

Thanks, 谢谢,

It's the smaller of 1024 or the compressed size. 它是1024或压缩大小中的较小者。

RFC2616 section 14 says: RFC2616第14节说:

" [ The rest of this answer has no relevance to the actual question asked. I'm leaving it in because some people found it useful. ] “[这个答案的其余部分与提出的实际问题无关。我将其留下,因为有些人发现它很有用。]

RFC 2616 has this to say (amongst other things) about Content-Length: 关于Content-Length,RFC 2616对此(以及其他内容)有这样的说法:

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. 应用程序应该使用此字段来指示消息正文的传输长度,除非4.4节中的规则禁止这样做。

So we have to figure out what transfer-length is; 所以我们必须弄清楚转移长度是多少; Section 4.4 (Message Length) says these two things about transfer-length: 第4.4节 (消息长度)说这两个关于传输长度的事情:

The transfer-length of a message is the length of the message-body as it appears in the message; 消息的传输长度是消息中出现的消息体的长度; that is, after any transfer-codings have been applied. 也就是说,在应用任何转移编码之后。

If a Content-Length header field (section 14.13) is present, its decimal value in OCTETs represents both the entity-length and the transfer-length. 如果存在Content-Length头字段(第14.13节),则其在OCTET中的十进制值表示实体长度和传输长度。 The Content-Length header field MUST NOT be sent if these two lengths are different 如果这两个长度不同,则不得发送Content-Length头字段

Okay, so we know that in this case transfer-length, entity-length, and Content-Length all have the same value, and all refer to "the length of the message-body as it appears in the message", and so we have to determine what message-body is. 好的,所以我们知道在这种情况下,transfer-length,entity-length和Content-Length都具有相同的值,并且都指的是“消息体中出现的消息体的长度”,所以我们必须确定什么是消息体。 Section 4.3 says this about message-body: 第4.3节说明了关于消息体的内容:

The message-body (if any) of an HTTP message is used to carry the entity-body associated with the request or response." HTTP消息的消息体(如果有的话)用于携带与请求或响应相关联的实体主体。“

So what's an entity-body? 那么什么是实体 - 身体? For that you have to refer to basically all of Section 7 . 为此你必须首先参考第7节的所有内容。 (Which also defines entity-length.) Most importantly, there this: (这也定义了实体长度。)最重要的是,有:

entity-body := Content-Encoding( Content-Type( data ) ) entity-body:=内容编码(内容类型(数据))

The length of the entity-body (and therefore our value for Content-Length per 4.4) is the length of the data after content-coding. 实体主体的长度(因此我们的每4.4内容长度的值)是内容编码后的数据长度。

The actual content length depends on the transfer encoding and data: If you use identity , no compression is applied and the content length is 1024; 实际内容长度取决于传输编码和数据:如果使用标识 ,则不应用压缩,内容长度为1024; if you use gzip , the actual content length depends on the data that is to be compressed. 如果使用gzip ,实际内容长度取决于要压缩的数据。

实际上它将是1024,这是压缩数据的大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM