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");