1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00

ESP8266WebServer: send empty chunk when done sending chunked response

Fixes https://github.com/esp8266/Arduino/issues/3225
This commit is contained in:
Ivan Grokhotkov 2017-12-14 11:10:01 +08:00 committed by Ivan Grokhotkov
parent 9b3583d227
commit 4c08389961
2 changed files with 24 additions and 9 deletions

View File

@ -433,6 +433,9 @@ void ESP8266WebServer::sendContent(const String& content) {
_currentClient.write(content.c_str(), len);
if(_chunked){
_currentClient.write(footer, 2);
if (len == 0) {
_chunked = false;
}
}
}
@ -453,6 +456,9 @@ void ESP8266WebServer::sendContent_P(PGM_P content, size_t size) {
_currentClient.write_P(content, size);
if(_chunked){
_currentClient.write(footer, 2);
if (size == 0) {
_chunked = false;
}
}
}
@ -560,19 +566,27 @@ void ESP8266WebServer::_handleRequest() {
}
#endif
}
if (!handled) {
if(_notFoundHandler) {
if (!handled && _notFoundHandler) {
_notFoundHandler();
handled = true;
}
else {
if (!handled) {
send(404, "text/plain", String("Not found: ") + _currentUri);
handled = true;
}
if (handled) {
_finalizeResponse();
}
_currentUri = String();
}
void ESP8266WebServer::_finalizeResponse() {
if (_chunked) {
sendContent("");
}
}
String ESP8266WebServer::_responseCodeToString(int code) {
switch (code) {
case 100: return F("Continue");

View File

@ -142,6 +142,7 @@ template<typename T> size_t streamFile(T &file, const String& contentType){
protected:
void _addRequestHandler(RequestHandler* handler);
void _handleRequest();
void _finalizeResponse();
bool _parseRequest(WiFiClient& client);
void _parseArguments(String data);
static String _responseCodeToString(int code);