Skip to content

WebServer.handleClient delay #4350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions libraries/WebServer/src/WebServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -66,6 +67,7 @@ WebServer::WebServer(int port)
, _currentVersion(0)
, _currentStatus(HC_NONE)
, _statusChange(0)
, _nullDelay(true)
, _currentHandler(nullptr)
, _firstHandler(nullptr)
, _lastHandler(nullptr)
Expand Down Expand Up @@ -280,6 +282,9 @@ void WebServer::handleClient() {
if (_currentStatus == HC_NONE) {
WiFiClient client = _server.available();
if (!client) {
if (_nullDelay) {
delay(1);
}
return;
}

Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions libraries/WebServer/src/WebServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class WebServer
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);

Expand Down Expand Up @@ -176,6 +177,7 @@ class WebServer
uint8_t _currentVersion;
HTTPClientStatus _currentStatus;
unsigned long _statusChange;
boolean _nullDelay;

RequestHandler* _currentHandler;
RequestHandler* _firstHandler;
Expand Down