What happens in the HTTP response to a GET request without Content-Length or Transfer-encoding?

If the response to the GET request does not contain the Content-Length or Transfer-encoding: chunked field, what happens? How does the client know when the message ends?

+5
source share
2 answers

RFC 7230 section 3.3.3 provides a good checklist of conditions for finding message body size. Essentially, he says the answer depends on the status code. The relevant conditions are # 1 and # 7.

"1. Any answer ... with 1xx (Informational), 204 (without content) or 304 (unchanged) status, the code always ends with the first empty line after the header fields, regardless of the header fields present in the message and therefore cannot contain the body of the message. "

"7. Otherwise, this is a response message without an announced message, body length, so the message body length is determined by the number of octets received before the server closes the connection ."

It is also worth knowing that the message may continue after the end of the body part. RFC 7230 Section 4.4 defines Trailers where a second set of mime headers can follow a payload. If they exist, the message ends where they are.

+1
source

According to specification

The message body length is determined by one of the following (in order of priority):

  • [...]
  • Otherwise, this is a response message without an announced message body length, so the message body length is determined by the number of octets received before the server closes the connection.

The client must detect that the connection is closed.

0
source

All Articles