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.
This commit is contained in:
keptn42 authored and StillDeadcode committed 2026-11-16 17:57:46 +01:00
1 parent b27f352259
commit aadabde0de
2 files changed
+20 -1

No files matched your search

+6 -1
View File
@@ -356,7 +356,12 @@ HttpResponse Router::dispatch(HttpRequest req) const {
bool path_matched = false;
std::map<std::string, std::string> 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);
}