Skip to content

Commit 11febf4

Browse files
committed
ESP8266WebServer: send empty chunk when done sending chunked response
Fixes #3225
1 parent 44c124b commit 11febf4

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

libraries/ESP8266WebServer/src/ESP8266WebServer.cpp

+22-8
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,9 @@ void ESP8266WebServer::sendContent(const String& content) {
433433
_currentClient.write(content.c_str(), len);
434434
if(_chunked){
435435
_currentClient.write(footer, 2);
436+
if (len == 0) {
437+
_chunked = false;
438+
}
436439
}
437440
}
438441

@@ -453,6 +456,9 @@ void ESP8266WebServer::sendContent_P(PGM_P content, size_t size) {
453456
_currentClient.write_P(content, size);
454457
if(_chunked){
455458
_currentClient.write(footer, 2);
459+
if (size == 0) {
460+
_chunked = false;
461+
}
456462
}
457463
}
458464

@@ -560,19 +566,27 @@ void ESP8266WebServer::_handleRequest() {
560566
}
561567
#endif
562568
}
563-
569+
if (!handled && _notFoundHandler) {
570+
_notFoundHandler();
571+
handled = true;
572+
}
564573
if (!handled) {
565-
if(_notFoundHandler) {
566-
_notFoundHandler();
567-
}
568-
else {
569-
send(404, "text/plain", String("Not found: ") + _currentUri);
570-
}
574+
send(404, "text/plain", String("Not found: ") + _currentUri);
575+
handled = true;
576+
}
577+
if (handled) {
578+
_finalizeResponse();
571579
}
572-
573580
_currentUri = String();
574581
}
575582

583+
584+
void ESP8266WebServer::_finalizeResponse() {
585+
if (_chunked) {
586+
sendContent("");
587+
}
588+
}
589+
576590
String ESP8266WebServer::_responseCodeToString(int code) {
577591
switch (code) {
578592
case 100: return F("Continue");

libraries/ESP8266WebServer/src/ESP8266WebServer.h

+1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ template<typename T> size_t streamFile(T &file, const String& contentType){
142142
protected:
143143
void _addRequestHandler(RequestHandler* handler);
144144
void _handleRequest();
145+
void _finalizeResponse();
145146
bool _parseRequest(WiFiClient& client);
146147
void _parseArguments(String data);
147148
static String _responseCodeToString(int code);

0 commit comments

Comments
 (0)