HTTP response without content-length doesn't work

  • Thread starter Thread starter Swamp Thing
  • Start date Start date
Click For Summary
SUMMARY

The discussion centers on the requirement of the Content-Length header in HTTP responses when using a NodeMCU ESP8266 board. Omitting the Content-Length results in failures in Chrome and Firefox, which either display a blank page or report a "Connection was reset" error. The HTTP response provided indicates that without Content-Length, browsers cannot properly interpret the end of the response body. The Content-Length header is essential for messages containing entity bodies unless chunked transfer encoding is utilized.

PREREQUISITES
  • Understanding of HTTP response headers
  • Familiarity with NodeMCU ESP8266 web server functionality
  • Knowledge of browser behavior regarding HTTP responses
  • Basic concepts of chunked transfer encoding
NEXT STEPS
  • Research "HTTP Content-Length header requirements"
  • Explore "NodeMCU ESP8266 web server configuration"
  • Learn about "HTTP chunked transfer encoding"
  • Investigate "Browser handling of HTTP responses without Content-Length"
USEFUL FOR

Web developers, embedded system programmers, and anyone troubleshooting HTTP response issues on NodeMCU ESP8266 boards.

Swamp Thing
Insights Author
Messages
1,047
Reaction score
785
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   Reactions: Swamp Thing

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
4K
  • · Replies 1 ·
Replies
1
Views
7K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 75 ·
3
Replies
75
Views
7K