What does “content-length” mean in HTTP?
In HTTP, content-length indicates the length of the entity body (in bytes) in an HTTP message (such as a request or response). It indicates the actual length of the message that the recipient needs to read and parse.
In a request message, the content-length is used to indicate the length of the request body, ensuring that the server can properly read the data being requested. This is crucial for POST requests and submitting form data.
In response messages, the content-length is used to indicate the length of the response body so that clients can read the response data correctly.
There are advantages to using content-length:
- The recipient can accurately determine the length of the actual message before reading it, allowing for correct handling of transmission and parsing.
- It can prevent the recipient from attempting to read a message that was not fully transmitted.
It should be noted that if a compression algorithm, such as gzip, is used, the content-length will represent the length of the compressed entity body, not the original entity body length.