diff --git a/libraries/WebServer/src/WebServer.cpp b/libraries/WebServer/src/WebServer.cpp index 048bd529d7b..92623b79c01 100644 --- a/libraries/WebServer/src/WebServer.cpp +++ b/libraries/WebServer/src/WebServer.cpp @@ -333,15 +333,28 @@ bool WebServer::removeRoute(const String &uri) { } bool WebServer::removeRoute(const String &uri, HTTPMethod method) { - // Loop through all request handlers and see if there is a match + bool anyHandlerRemoved = false; RequestHandler *handler = _firstHandler; + RequestHandler *previousHandler = nullptr; + while (handler) { if (handler->canHandle(method, uri)) { - return _removeRequestHandler(handler); + if (_removeRequestHandler(handler)) { + anyHandlerRemoved = true; + // Move to the next handler + if (previousHandler) { + handler = previousHandler->next(); + } else { + handler = _firstHandler; + } + continue; + } } + previousHandler = handler; handler = handler->next(); } - return false; + + return anyHandlerRemoved; } void WebServer::addHandler(RequestHandler *handler) {