Repository navigation
refactor(gateway): REST proxying in its own module; Gateway keeps the route handlers - #167
Conversation
|
Local run of Every proxy- and card-path test passed: 16 failures, all from this machine and none in the moved code: 11 |
1fad9fb to
6a9a432
Compare
5f76657 to
7ace4a1
Compare
… route handlers The /svc and /website reverse proxy (path forwarded as received, raw header multiplicity, the gateway's role header and JSON-RPC _meta stamp, the streamed upstream response that closes itself) and the backing servers' card rewrite now live in rest_proxy.py as module functions. Gateway._proxy_rest_request resolves the service and hands off; _rewrite_child_card and _fetch_child_card stay as thin methods, since tests override them per instance. The request-scope binder reads the raw role header name from the new module. No wire change: same URLs, headers, _meta keys and values, same error bodies. gateway.py goes from 1361 to 1137 lines. The doctest runner now covers both modules, since the examples moved with their functions. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
6a9a432 to
418d6fa
Compare
|
Light chaos round on this head (418d6fa), loopback, aimed at the moved proxy: a real
|
Third of the gateway maintainability stack, rebased onto
mainafter #165 and #166 merged. Behaviour-neutral: no wire change.What moved. The
/svcand/websitereverse proxy and the backing servers' card rewrite now live insrc/agent_env/env/gateway/rest_proxy.pyas module functions, with the invariants stated once in the module docstring:forward(request, base_url, *, role, timeout, mcp_server)is the former_proxy_rest_requestbody: the path forwarded as received (upstream_url/raw_remainder), one header per raw entry minus hop-by-hop and the client's role header (upstream_headers), the JSON-RPC_metarole stamp on a backing MCP server's own endpoint (is_child_mcp_path,stamp_jsonrpc_role), and the streamedUpstreamResponsethat closes itself.fetch_child_card,rewrite_child_card(key, card, gateway_extensions)andoperationsare the env-card side of the same/svc/{key}prefix.What
Gatewaykeeps._proxy_rest_requestresolves the service and hands off: "is this a backing MCP server" stays with the gateway, which knows its services; "is this its MCP endpoint" goes with the proxy._rewrite_child_cardand_fetch_child_cardstay as thin methods because tests override them per instance._request_rolestays, since/stepreads it too. The request-scope binder reads the raw role header name from the new module.gateway.pygoes from 1361 to 1137 lines.Tests.
tst/unit/env/gateway: 377 passed after the rebase ontomain, the same count as before the move. Together with the card-consuming suites outside it (test_env.py,test_env_card_loads.py, the task_step snapshot/sync/apply tests): 557 passed. The only test edits are the doctest runner, which now covers both modules since the examples moved with their functions, and thehttpx.AsyncClientmonkeypatch pointing at the module that constructs the client.🤖 Generated with Claude Code


Confidence Score: 5/5
The PR appears safe to merge; no actionable regression was found.Summary
Moves REST forwarding and child-card rewriting into
rest_proxy.py, whileGatewaykeeps route handlers and service selection.rest_proxymodule forwards service requests and streams replies.rest_proxymodule fetches and rewrites backing-server cards.Diagram
%%{init: {'theme': 'neutral'}}%% flowchart LR C[Client] --> G[Gateway route handler] G -->|Service URL and role| P[rest_proxy.forward] P --> S[Backing service] S --> U[UpstreamResponse] U --> C G --> F[fetch_child_card] F --> R[rewrite_child_card] R --> E[Composed environment card]Reviews (3) · Last reviewed commit: "refactor(gateway): REST proxying in its ..." · Reviewed by Greptile