HTTP response without content-length doesn't work

  • Thread starter Thread starter Swamp Thing
  • Start date Start date
AI Thread Summary
When using the web server feature on a NodeMCU ESP8266 board, omitting the Content-Length header in the HTTP response leads to issues in web browsers like Chrome and Firefox, which fail to display the page. Chrome shows a blank page, while Firefox indicates "Connection was reset." The HTTP response received via Telnet confirms that the connection is closed after sending a simple HTML message. Despite the presence of the "Connection: close" header, the absence of Content-Length causes errors in tools like Curl and Wget as well. It is noted that the Content-Length header is essential for messages containing entity bodies unless chunked transfer encoding is utilized, which is not being applied in this case.
Swamp Thing
Insights Author
Messages
1,031
Reaction score
769
I am trying out the web server feature on a NodeMCU ESP8266 board. If I include a Content-Length line in the response header, it works perfectly.

But if I omit the content-length, then Chrome and Firefox fail to display the page. Chrome displays a blank page, and Firefox says "Connection was reset".

This is the HTTP response as received on Telnet:
Code:
HTTP/1.1 200 OK
Content-Type: text/html
Connection: close

<html><body>Hello</body></html>
Connection closed by foreign host.
(There is a "\r\n" at the end of each line and after the header).

Curl and Wget also report "connection closed" errors.

My understanding is that if content-length is not specified, then closing the connection is a valid way to signal end of data. Especially with "connection: close". So what is the problem?
 
Technology news on Phys.org
  • Like
Likes Swamp Thing
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Thread 'Project Documentation'
Trying to package up a small bank account manager project that I have been tempering on for a while. One that is certainly worth something to me. Although I have created methods to whip up quick documents with all fields and properties. I would like something better to reference in order to express the mechanical functions. It is unclear to me about any standardized format for code documentation that exists. I have tried object orientated diagrams with shapes to try and express the...
Back
Top