Repository navigation
Lift URL and header handling into tw-upstream - #135
Merged
Merged
Conversation
`forward` is where this gateway talks to an upstream, and most of it does not know it is this gateway: assembling a URL from base + path + query, deciding which client headers travel onward, deciding which upstream headers come back. Ten items, no dependency beyond `http`. That is exactly the shape the enterprise gateway needs. It reaches its upstreams through `tw-provider`, which is built around a DTO and cannot carry a request that was already converted — and converting is the whole point of the dialect layer. What replaces it is this: a prepared body, a path, a query, and headers. Four things stay behind because they are not general: `apply_set` and `check_body_size` need the rule engine, `map_reqwest_error` needs the secret layer, and `should_strip`'s sibling logic is tied to neither so it moves. Deliberately absent: the HTTP client. The two gateways have opposite policies and both are right. Desktop sets no overall timeout because a six-minute task should not be cut off by something in the middle, and keeps HTTP/2 pings alive because a desktop behind Clash or Surge loses idle connections silently. The enterprise side sets 300 seconds and refuses redirects, because it is multi-tenant and its base URLs are typed in by an admin. Merging those would impose one deployment's assumptions on the other. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Next step toward retiring
tw-provider. Before the enterprise gateway can send a request thattw-dialectalready converted, there has to be somewhere to send it from.What moves
Ten items out of
tw-gateway/src/forward.rsinto a newtw-upstreamcrate — URL assembly, which client headers travel onward, which upstream headers come back. One dependency:http.None of it knows it is this gateway.
upstream_url(base_url, path, query)is already the exact shapetw_dialect::convert::Preparedhands over.It also carries the comment worth keeping visible:
What stays behind
apply_setandcheck_body_sizeneed the rule engine;map_reqwest_errorneeds the secret layer. Those are this gateway's, not shared.What is deliberately not in here: the HTTP client
Both gateways build one, and the policies are opposite — and both are right for where they run:
Merging them would impose one deployment's assumptions on the other. Each keeps its own.
(Two gaps that comparison exposed, noted for separate work: desktop does not refuse redirects though its base URLs are equally user-supplied, and the enterprise client has no HTTP/2 keep-alive though it can sit behind NAT too.)
Verification
Nine tests move with the code.
cargo fmt --check,clippy --workspace --all-targets -- -D warnings, 87 test binaries green.🤖 Generated with Claude Code