Unverified Commit 08ef6253 authored by Ayush Sharma's avatar Ayush Sharma Committed by GitHub

fix: removeRoute should remove all matching routes (#9851)

parent 3428eb6a
...@@ -333,15 +333,28 @@ bool WebServer::removeRoute(const String &uri) { ...@@ -333,15 +333,28 @@ bool WebServer::removeRoute(const String &uri) {
} }
bool WebServer::removeRoute(const String &uri, HTTPMethod method) { 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 *handler = _firstHandler;
RequestHandler *previousHandler = nullptr;
while (handler) { while (handler) {
if (handler->canHandle(method, uri)) { 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(); handler = handler->next();
} }
return false;
return anyHandlerRemoved;
} }
void WebServer::addHandler(RequestHandler *handler) { void WebServer::addHandler(RequestHandler *handler) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment