Repository navigation
fix(forward): don't repeat the version segment a base URL ends with - #212
Merged
Merged
Conversation
Provider docs often give the base URL with its version segment (`https://api.openai.com/v1`), and clients send paths that start with it (`/v1/chat/completions`). The two were joined as they were, so such an upstream got `.../v1/v1/chat/completions` and a 404 on every request and every connection check, although the configuration reference says to write the base URL up to the version segment. `upstream_url` now drops the path's first segment when the base URL's path ends with the same version segment (`v1`, `v2`, `v1beta`, ...). Any other segment is joined as before: the same name there says nothing about it being the same segment. A base URL without a path is not affected, including a host that happens to be called `v1`. Both gateways build upstream URLs with this function, so the enterprise edition gets the same behaviour when it moves to this version. Co-Authored-By: Claude Opus 5.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.
Summary
An upstream whose base URL ends with its version segment, as provider docs usually give it (
https://bedrock-mantle.us-east-1.api.aws/v1,https://api.openai.com/v1), got every request and every connection check sent to.../v1/v1/..., because the client's path (/v1/chat/completions) was appended as it was. The configuration reference already says to write the base URL up to the version segment, so the documented form did not work.tw_dialect::url::upstream_urlnow drops the path's first segment when the base URL's path ends with the same version segment:https://api.openai.com/v1/v1/chat/completionshttps://api.openai.com/v1/chat/completionshttps://generativelanguage.googleapis.com/v1beta/v1beta/models/m:streamGenerateContent.../v1beta/models/m:streamGenerateContenthttps://relay.example/anthropic/v1/messages.../anthropic/v1/messageshttps://x.example/v1/v1beta/models/mhttps://x.example/api/api/itemshttp://v1:8080/v1/messagesv1is the host, not a path segmentOnly
v+ digits, optionally followed byalpha/betaand digits, counts as a version segment. The same name elsewhere says nothing about it being the same segment.The enterprise edition builds its upstream URLs with the same function, so it gets this when it moves to a version that includes it.
Test plan
cargo fmt --all --checkcargo clippy --workspace --all-targets -- -D warningscargo test --workspace(new cases intw-dialecturl::tests)🤖 Generated with Claude Code