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:
@@ -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", "*");
|
||||
|
||||
|
Reference in New Issue
Block a user