HTTP Content-Length

来自WHY42

The Content-Length header indicates the size of the message body, in bytes, sent to the recipient.

Content-Length: <length>

The Content-Length header is not mandatory in HTTP responses, but it is recommended for responses that have a body. The header specifies the length of the message body in octets (8-bit bytes) and allows the recipient to accurately determine the message size and prevent buffer overflows. However, for responses that use chunked transfer encoding, the Content-Length header is not necessary, as the chunked encoding itself indicates the message length.

When no Content-Length is received, the client keeps reading until the server closes the connection.[1]