HTTP response without content-length doesn't work

  • Thread starter Thread starter Swamp Thing
  • Start date Start date
Click For 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,045
Reaction score
775
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
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 3 ·
Replies
3
Views
13K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 31 ·
2
Replies
31
Views
3K
  • · Replies 1 ·
Replies
1
Views
7K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 75 ·
3
Replies
75
Views
7K