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.
source share