content-length when using http compression

后端 未结 3 1578
死守一世寂寞
死守一世寂寞 2020-12-05 17:32

The client is making a range request 0-1023 to the http server. It prefers gzip compression with Accept-Encoding: gzip;q=1.0, identity; q=0.5, *;q=0 in the request.

<
相关标签:
3条回答
  • 2020-12-05 18:06

    Actually it will be 1024 which is the size of compressed data.

    0 讨论(0)
  • 2020-12-05 18:07

    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; if you use gzip, the actual content length depends on the data that is to be compressed.

    0 讨论(0)
  • 2020-12-05 18:20

    It's the smaller of 1024 or the compressed size.

    RFC2616 section 14 says:

    " [ 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:

    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.

    So we have to figure out what transfer-length is; Section 4.4 (Message Length) says these two things about transfer-length:

    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. The Content-Length header field MUST NOT be sent if these two lengths are different

    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. Section 4.3 says this about message-body:

    The message-body (if any) of an HTTP message is used to carry the entity-body associated with the request or response."

    So what's an entity-body? For that you have to refer to basically all of Section 7. (Which also defines entity-length.) Most importantly, there this:

    entity-body := Content-Encoding( Content-Type( data ) )

    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.

    0 讨论(0)
提交回复
热议问题