Skip to content

refactor: table-driven endpoint dispatch - #130

Merged
dolonet merged 1 commit into
dolonet:mainfrom
gorevds:refactor/route-dispatch-table
Jun 25, 2026
Merged

refactor: table-driven endpoint dispatch#130
dolonet merged 1 commit into
dolonet:mainfrom
gorevds:refactor/route-dispatch-table

Conversation

@gorevds

@gorevds gorevds commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

What

Replaces the if/elif chains in do_POST/do_GET/do_DELETE with one class-level route table per HTTP method (_POST_ROUTES/_GET_ROUTES/_DELETE_ROUTES, action → handler-method name) and a four-line _dispatch(). The config/ping inline branches became tiny _config/_ping methods.

Adding an endpoint is now one table row — and the server-side action set is machine-readable.

New guard test

test_server_routes_are_routed_by_php_proxy cross-checks the route tables against api.php's switch: an endpoint added on the Python side but forgotten in the PHP shim previously silently 404'd only on shared hosting (the existing coverage test only checked frontend-called actions). This closes that gap.

Preserved exactly

  • Route sets per method identical (10 POST / 7 GET / 1 DELETE), incl. the save_delete POST compatibility row with its comment
  • Static-file precedence in do_GET (checked before action resolution)
  • Both URL dialects (/api/<action> and api.php?action=) via the untouched _resolve_action
  • Unknown/empty action → same {"error": "not found"} 404
  • No getattr injection surface: the attacker-controlled action string is only a dict key; only hardcoded table values reach getattr

Tests

487 backend tests OK (486 + the new guard).

Replace the if/elif chains in do_POST/do_GET/do_DELETE with one
class-level route table per HTTP method plus a four-line _dispatch().
Adding an endpoint is now one table row, and the server-side action
set is machine-readable - a new coverage test cross-checks it against
api.php's switch so an endpoint added on the Python side can no longer
silently 404 on shared hosting.

The action string is only ever used as a dict key; only hardcoded
table values reach getattr. Static-file precedence in do_GET, both
URL dialects, the save_delete POST compatibility row, and the 404
fallthrough are preserved exactly.
@dolonet
dolonet merged commit 6b08ced into dolonet:main Jun 25, 2026
7 checks passed
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.

2 participants