Archived
server: the guarded-route set is declared once, at registration
The front kept its own list of which routes answer the local operator
keyless -- guarded_route spelled out the same eight (method, path)
pairs Server::register_routes registers with a local_operator handler,
and its comment admitted the copy ("Kept in step with Server::register
routes"). A new guarded route meant editing the registration AND the
front's list AND the test that pins the list against drift; miss one and
the front wakes a parked model for a stranger who is then refused -- the
exact A-05 bug class -- silently.
Router::add now takes a `guarded` flag, set on the six registrations
that guard (and their DELETE siblings). Router::guarded(method, path)
asks the matcher -- the same split_path + :label match that reaches the
handler -- and the front copies the flag as it mirrors each model route,
so guarded_route is one line reading the front's own copied marks. One
declaration per guarded route, at its registration; the matcher that
decides the wake is the matcher that dispatches, so slash and :label
forms cannot disagree with the handler and the drift risk is gone.
front_test still pins every shape (guarded: slashes, /sessions/:label,
the trailing-slash collapse; not: GET /sessions, /stats, inference,
/sessions/a/b) and transport_test exercises real dispatch through them.
Behaviour unchanged -- the same eight routes wake nothing for a stranger.
This commit is contained in:
1 parent
0f011f27e1
commit
66b0dcf019
6 files changed
+70
-45
No files matched your search
@@ -250,8 +250,8 @@ static std::vector<std::string> split_path(const std::string& p) {
|
||||
return out;
|
||||
}
|
||||
|
||||
void Router::add(std::string method, std::string path, Handler h) {
|
||||
routes_.push_back(Route{std::move(method), split_path(path), std::move(h)});
|
||||
void Router::add(std::string method, std::string path, Handler h, bool guarded) {
|
||||
routes_.push_back(Route{std::move(method), split_path(path), std::move(h), guarded});
|
||||
}
|
||||
|
||||
void Router::socket(std::string path, SocketHandler h) {
|
||||
@@ -346,6 +346,12 @@ bool Router::allows(const std::string& method, const std::string& path) const {
|
||||
return match(method, split_path(path), nullptr, &path_matched) != nullptr;
|
||||
}
|
||||
|
||||
bool Router::guarded(const std::string& method, const std::string& path) const {
|
||||
bool path_matched = false;
|
||||
const Route* r = match(method, split_path(path), nullptr, &path_matched);
|
||||
return r && r->guarded;
|
||||
}
|
||||
|
||||
HttpResponse Router::dispatch(HttpRequest req) const {
|
||||
bool path_matched = false;
|
||||
std::map<std::string, std::string> caps;
|
||||
|
||||
Reference in new issue
Block a user