Skip to content

Commit 5a2af54

Browse files
committed
WebServer: catch the case when request isn't handled
If RequestHandler::canHandle returns true, but subsequent RequestHandler::handle returns false, we should return some HTTP response instead of an empty one.
1 parent e6a53c1 commit 5a2af54

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

libraries/ESP8266WebServer/src/ESP8266WebServer.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,19 +362,28 @@ void ESP8266WebServer::onNotFound(THandlerFunction fn) {
362362
}
363363

364364
void ESP8266WebServer::_handleRequest() {
365+
bool handled = false;
365366
if (!_currentHandler){
366367
#ifdef DEBUG
367368
DEBUG_OUTPUT.println("request handler not found");
368369
#endif
370+
}
371+
else {
372+
handled = _currentHandler->handle(*this, _currentMethod, _currentUri);
373+
#ifdef DEBUG
374+
if (!handled) {
375+
DEBUG_OUTPUT.println("request handler failed to handle request");
376+
}
377+
#endif
378+
}
369379

380+
if (!handled) {
370381
if(_notFoundHandler) {
371382
_notFoundHandler();
372383
}
373384
else {
374385
send(404, "text/plain", String("Not found: ") + _currentUri);
375386
}
376-
} else {
377-
_currentHandler->handle(*this, _currentMethod, _currentUri);
378387
}
379388

380389
uint16_t maxWait = HTTP_MAX_CLOSE_WAIT;

0 commit comments

Comments
 (0)