Search code examples
htmlapachehttpserver

What is the use of Content-Length header in http response? It is necessary to pass the header? What if the value if more or less than actual content?


I want to understand the working of Content-Length header and how broswers and servers treat it. I have seen responses without centent-length header and some with content-length. Also, I have seen responses with less value than the actual message body size and browser tuncates the content. I want to know the best practices around the header.


Solution

  • These days, you either need to send an appropriate Content-Length in your header, or you need to send your response in chunked transfer encoding. An HTTP response with less data than expected is an error.