Retrieving Content
The Content-length header
specifies the length of the data (in bytes) that is returned by the
server. Due to the dynamic nature of some requests, the
Content-length is sometimes unknown, and this
header might be omitted.
There are three common ways that a client can retrieve data from the entity-body of the server’s response:
The first method involves retrieving the size of the document from the
Content-lengthheader, and then reading in that much data from the network connection. Using this method, the client knows the size of the document before retrieving it.In other cases, when the size of the document is too dynamic for a server to predict, the
Content-lengthheader is omitted. When this happens, the client reads in the data portion of the server’s response until the server disconnects the network connection. This practice is obsolete and only works in HTTP 1.0. For generating data without knowing the total message length in advance, the next method is recommended.Another header could indicate when an entity-body ends, like HTTP 1.1’s
Transfer-Encodingheader with thechunkedparameter.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access