Skip to content

Fix HttpService route precedence so Any("*") no longer shadows specific handlers#832

Draft
Copilot wants to merge 3 commits into
masterfrom
copilot/fix-httpservice-getroute-issue
Draft

Fix HttpService route precedence so Any("*") no longer shadows specific handlers#832
Copilot wants to merge 3 commits into
masterfrom
copilot/fix-httpservice-getroute-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 18, 2026

HttpService::GetRoute(HttpRequest*, ...) iterated pathHandlers via std::unordered_map, so match order was non-deterministic. In practice, a catch-all Any("*") could win before concrete routes (e.g. /ping), breaking expected router behavior.

  • Routing precedence in HttpService::GetRoute(HttpRequest*, ...)

    • Added explicit exact-path lookup first (pathHandlers.find(path)), with normal method resolution.
    • Refactored pattern matching into deterministic phases:
      • RESTful patterns (/:id, /{id}) first
      • wildcard patterns (*) after
    • Added stable ordering among pattern candidates (longer path first, then lexical tie-break) to avoid unordered-map iteration effects.
  • Routing matcher extraction

    • Extracted route pattern matching into a helper (match_route_path) to keep wildcard + RESTful matching behavior consistent while making precedence explicit.
  • Focused regression test

    • Added unittest/http_service_route_test.cpp and wired it into unittest/CMakeLists.txt.
    • Test asserts:
      • specific route /ping is selected over Any("*")
      • unknown path still falls through to catch-all
HttpService service;
service.Any("*", fallback_handler);
service.GET("/ping", specific_handler);

// /ping resolves to specific handler, not catch-all

Copilot AI and others added 2 commits May 18, 2026 07:12
Copilot AI changed the title [WIP] Fix HttpService route matching for specific handlers Fix HttpService route precedence so Any("*") no longer shadows specific handlers May 18, 2026
Copilot AI requested a review from ithewei May 18, 2026 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HttpService::GetRoute first-match-wins over std::unordered_map breaks ANY("*") + specific routes

2 participants