@@ -217,7 +217,7 @@ struct HttpRouter {
217217 std::string segment = std::string (getUrlSegment (i).first );
218218 Node *next = nullptr ;
219219 for (std::unique_ptr<Node> &child : n->children ) {
220- if (child->name == segment && child->isHighPriority == (priority == HIGH_PRIORITY)) {
220+ if (((segment. length () && child->name . length () && segment[ 0 ] == ' : ' && child-> name [ 0 ] == ' : ' ) || child-> name == segment) && child->isHighPriority == (priority == HIGH_PRIORITY)) {
221221 next = child.get ();
222222 break ;
223223 }
@@ -271,7 +271,10 @@ struct HttpRouter {
271271 }
272272 }
273273
274- /* Always test any route last */
274+ /* Always test any route last (this check should not be necessary if we always have at least one handler) */
275+ if (root.children .empty ()) [[unlikely]] {
276+ return false ;
277+ }
275278 return executeHandlers (root.children .back ().get (), 0 , userData);
276279 }
277280
@@ -356,11 +359,11 @@ struct HttpRouter {
356359 /* Removes ALL routes with the same handler as can be found with the given parameters.
357360 * Removing a wildcard is done by removing ONE OF the methods the wildcard would match with.
358361 * Example: If wildcard includes POST, GET, PUT, you can remove ALL THREE by removing GET. */
359- void remove (std::string method, std::string pattern, uint32_t priority) {
362+ bool remove (std::string method, std::string pattern, uint32_t priority) {
360363 uint32_t handler = findHandler (method, pattern, priority);
361364 if (handler == UINT32_MAX) {
362365 /* Not found or already removed, do nothing */
363- return ;
366+ return false ;
364367 }
365368
366369 /* Cull the entire tree */
@@ -371,6 +374,8 @@ struct HttpRouter {
371374
372375 /* Now remove the actual handler */
373376 handlers.erase (handlers.begin () + (handler & HANDLER_MASK));
377+
378+ return true ;
374379 }
375380};
376381
0 commit comments