Skip to content

Commit 9e61e60

Browse files
committed
A content length of zero should also be sent
This is needed since when the content-length header is not sent the clients will wait for data anyways. Sending a content length of zero will tell the client not to expect any content and it will close the connection immediately.
1 parent 5f80ad5 commit 9e61e60

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

libraries/ESP8266WebServer/src/ESP8266WebServer.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,10 @@ void ESP8266WebServer::_prepareHeader(String& response, int code, const char* co
213213
content_type = "text/html";
214214

215215
sendHeader("Content-Type", content_type, true);
216-
if (_contentLength != CONTENT_LENGTH_UNKNOWN && _contentLength != CONTENT_LENGTH_NOT_SET) {
217-
sendHeader("Content-Length", String(_contentLength));
218-
}
219-
else if (contentLength > 0){
216+
if (_contentLength == CONTENT_LENGTH_NOT_SET) {
220217
sendHeader("Content-Length", String(contentLength));
218+
} else if (_contentLength != CONTENT_LENGTH_UNKNOWN) {
219+
sendHeader("Content-Length", String(_contentLength));
221220
}
222221
sendHeader("Connection", "close");
223222
sendHeader("Access-Control-Allow-Origin", "*");

0 commit comments

Comments
 (0)