Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the Content-Length header required for a HTTP/1.0 response?

Is the Content-Length header required for a HTTP/1.0 response? The HTTP spec mentions that it is required for the request, but doesn't mention anything about the response:

http://www.w3.org/Protocols/HTTP/1.0/draft-ietf-http-spec.html#Content-Length

A valid Content-Length field value is required on all HTTP/1.0 request messages containing an entity body.

If it is not required for the response, how does the client read the response when it's larger than 1MB?

like image 899
Sean Nguyen Avatar asked Apr 13 '13 18:04

Sean Nguyen


People also ask

Which HTTP headers are mandatory?

Common Response HeadersThe first line of the response is mandatory and consists of the protocol ( HTTP/1.1),response code (200)and description (OK). The headers shown are: CONTENT-Type -This is Text/html which is a web page. It also includes the character set which is UTF-8.

What is the purpose of Content-Length header?

The Content-Length entity-header field indicates the size of the entity-body, in decimal number of OCTETs, sent to the recipient or, in the case of the HEAD method, the size of the entity-body that would have been sent had the request been a GET.

Is Content-Length set automatically?

When making a POST request, HTTP clients typically automatically add a Content-Length header based on the size of the data supplied and a Content-Type header based on the type of data being transferred.


1 Answers

Section 10.4 of the spec (which you linked to) doesn't say anything about requirements on responses itself, but instead links to section 7.2.2, which specifies that the server can indicate the length of a response containing an entity body by

  • sending a Content-Length header, or
  • closing the connection when the entire response has been sent.

Section 7.2 says that responses to HEAD requests, and 1xx, 204 or 304 responses, should not include an entity body, and therefore need not include a Content-Length header; and

All other responses must include an entity body or a Content-Length header field defined with a value of zero (0).

So to answer the question: When no Content-Length is received, the client keeps reading until the server closes the connection.

like image 52
michaelb958--GoFundMonica Avatar answered Oct 11 '22 12:10

michaelb958--GoFundMonica