diff --git a/libraries/WebServer/src/WebServer.cpp b/libraries/WebServer/src/WebServer.cpp index e686f2fc..e4ffdf54 100644 --- a/libraries/WebServer/src/WebServer.cpp +++ b/libraries/WebServer/src/WebServer.cpp @@ -45,6 +45,7 @@ WebServer::WebServer(IPAddress addr, int port) , _currentVersion(0) , _currentStatus(HC_NONE) , _statusChange(0) +, _nullDelay(true) , _currentHandler(nullptr) , _firstHandler(nullptr) , _lastHandler(nullptr) @@ -66,6 +67,7 @@ WebServer::WebServer(int port) , _currentVersion(0) , _currentStatus(HC_NONE) , _statusChange(0) +, _nullDelay(true) , _currentHandler(nullptr) , _firstHandler(nullptr) , _lastHandler(nullptr) @@ -280,6 +282,9 @@ void WebServer::handleClient() { if (_currentStatus == HC_NONE) { WiFiClient client = _server.available(); if (!client) { + if (_nullDelay) { + delay(1); + } return; } @@ -370,6 +375,10 @@ void WebServer::setContentLength(const size_t contentLength) { _contentLength = contentLength; } +void WebServer::enableDelay(boolean value) { + _nullDelay = value; +} + void WebServer::enableCORS(boolean value) { _corsEnabled = value; } diff --git a/libraries/WebServer/src/WebServer.h b/libraries/WebServer/src/WebServer.h index a0d3a1c1..76609d6f 100644 --- a/libraries/WebServer/src/WebServer.h +++ b/libraries/WebServer/src/WebServer.h @@ -123,6 +123,7 @@ public: void send_P(int code, PGM_P content_type, PGM_P content); void send_P(int code, PGM_P content_type, PGM_P content, size_t contentLength); + void enableDelay(boolean value); void enableCORS(boolean value = true); void enableCrossOrigin(boolean value = true); @@ -176,6 +177,7 @@ protected: uint8_t _currentVersion; HTTPClientStatus _currentStatus; unsigned long _statusChange; + boolean _nullDelay; RequestHandler* _currentHandler; RequestHandler* _firstHandler;