1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-09-09 18:40:33 +03:00

Add setContentLength method to web server, update examples

related to #304
This commit is contained in:
Ivan Grokhotkov
2015-05-22 17:57:30 +03:00
parent 21d50e104c
commit 8fdb824e11
4 changed files with 62 additions and 58 deletions

View File

@@ -111,6 +111,7 @@ void ESP8266WebServer::handleClient()
}
_currentClient = client;
_contentLength = CONTENT_LENGTH_NOT_SET;
_handleRequest();
}
@@ -138,9 +139,13 @@ void ESP8266WebServer::send(int code, const char* content_type, String content)
if (!content_type)
content_type = "text/html";
String len(content.length());
sendHeader("Content-Type", content_type, true);
sendHeader("Content-Length", len.c_str());
if (_contentLength != CONTENT_LENGTH_UNKNOWN) {
size_t length = (_contentLength == CONTENT_LENGTH_NOT_SET) ?
content.length() : _contentLength;
String lengthStr(length);
sendHeader("Content-Length", lengthStr.c_str());
}
sendHeader("Connection", "close");
sendHeader("Access-Control-Allow-Origin", "*");