From aadabde0dec7567049ffa0927415c1ecd14e16e9 Mon Sep 17 00:00:00 2001 From: keptn42 Date: Sun, 15 Nov 2026 15:56:20 +0100 Subject: [PATCH] http: a route's captures replace those the request already carries Router::dispatch put a route's captures into the request with std::map::insert, which keeps a key the request already has. The front matches /v1/models/ID itself and hands the request to the model's router with the path rewritten, an alias as the model's name and base:adapter as the adapter's, so the model read the front's id: through the front, GET /v1/models/ALIAS and GET /v1/models/base:adapter answered 404. The captures of the route that matched now replace those of the same name; nothing sets a request's params before a dispatch otherwise. server_test: a_request_handed_on_reads_the_capture_of_the_route_that_matched_it fails without the change and passes with it. --- core/server/http.cpp | 7 ++++++- tests/server_test.cpp | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/core/server/http.cpp b/core/server/http.cpp index 1f08c66d..5da5816a 100644 --- a/core/server/http.cpp +++ b/core/server/http.cpp @@ -356,7 +356,12 @@ HttpResponse Router::dispatch(HttpRequest req) const { bool path_matched = false; std::map caps; if (const Route* r = match(req.method, split_path(req.path), &caps, &path_matched)) { - req.params.insert(caps.begin(), caps.end()); + /* The captures of the route that matched replace any of the same name the request already + * carries. The front matches a request once and hands it to the model's router with the + * path rewritten -- `base:adapter` as `adapter`, an alias as the model's name -- and the + * model must read what its own route captured: kept, the front's `id` made + * /v1/models/base:adapter and /v1/models/ALIAS a 404. */ + for (auto& [k, v] : caps) req.params[k] = std::move(v); return r->h(req); } diff --git a/tests/server_test.cpp b/tests/server_test.cpp index d0e84ea8..87682a7d 100644 --- a/tests/server_test.cpp +++ b/tests/server_test.cpp @@ -2694,6 +2694,20 @@ TEST(the_adaptive_draft_window_is_exposed_only_while_it_is_on) { CHECK_NEAR(value("radiance:draft_verify_depth_total" + L + ",depth=\"6\"}"), -1.0, 1e-9); } +/* The front matches /v1/models/ID itself and hands the request on with the path rewritten: an + * alias becomes the model's name, `base:adapter` the adapter's. The model's router reads the id its + * own route captured, not the front's, so the request still carries the front's capture here. */ +TEST(a_request_handed_on_reads_the_capture_of_the_route_that_matched_it) { + Fixture f; + HttpRequest q; + q.method = "GET"; + q.path = "/v1/models/test-model"; + q.params["id"] = "an-alias"; + const HttpResponse r = f.srv->router().dispatch(q); + CHECK_EQ(r.status, 200); + CHECK_EQ(json::parse(r.body).value("id", std::string()), std::string("test-model")); +} + TEST(models_and_health_answer) { Fixture f; HttpResponse r = f.get("/v1/models");