mirror of
https://github.com/esp8266/Arduino.git
synced 2025-09-09 18:40:33 +03:00
Make the web server not waste heap
added some helper methods as well
This commit is contained in:
@@ -101,7 +101,8 @@ void ESP8266WebServer::handleClient()
|
||||
#endif
|
||||
|
||||
// Wait for data from client to become available
|
||||
while(client.connected() && !client.available()){
|
||||
uint16_t maxWait = HTTP_MAX_DATA_WAIT;
|
||||
while(client.connected() && !client.available() && maxWait--){
|
||||
delay(1);
|
||||
}
|
||||
|
||||
@@ -136,7 +137,12 @@ 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());
|
||||
sendHeader("Connection", "close");
|
||||
sendHeader("Access-Control-Allow-Origin", "*");
|
||||
|
||||
response += _responseHeaders;
|
||||
response += "\r\n";
|
||||
@@ -145,6 +151,14 @@ void ESP8266WebServer::send(int code, const char* content_type, String content)
|
||||
sendContent(response);
|
||||
}
|
||||
|
||||
void ESP8266WebServer::send(int code, char* content_type, String content) {
|
||||
send(code, (const char*)content_type, content);
|
||||
}
|
||||
|
||||
void ESP8266WebServer::send(int code, String content_type, String content) {
|
||||
send(code, (const char*)content_type.c_str(), content);
|
||||
}
|
||||
|
||||
void ESP8266WebServer::sendContent(String content) {
|
||||
size_t size_to_send = content.length();
|
||||
size_t size_sent = 0;
|
||||
@@ -158,6 +172,10 @@ void ESP8266WebServer::sendContent(String content) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
uint16_t maxWait = HTTP_MAX_CLOSE_WAIT;
|
||||
while(_currentClient.connected() && maxWait--) {
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
|
||||
String ESP8266WebServer::arg(const char* name) {
|
||||
|
Reference in New Issue
Block a user