Skip to content

Commit

Permalink
fix: removeRoute should remove all matching routes (#9851)
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushsharma82 authored Jun 13, 2024
1 parent 3428eb6 commit 08ef625
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions libraries/WebServer/src/WebServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 08ef625

Please sign in to comment.