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,028
Reaction score
767
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
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top