Repository navigation
fix(api): keep the base path of the server URL in Twirp requests - #861
Merged
Merged
Conversation
Since region failover (livekit#733) the request URL is built from the bare origin, so a server URL with a path (reverse proxy) lost it. Use the configured host for the first attempt; fallback regions stay bare origins. Also drop the doubled slash in TwirpClient.host.
ANDROIDHASSAN
requested review from
changt,
cloudwebrtc,
lukasIO and
xianshijing-lk
as code owners
October 14, 2026 12:00
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.
Since the region-failover change (#733),
TwirpClient.requestbuilds every request URL fromself._origin, which isscheme://host[:port]only, so a base path in the server URL is dropped. Before #733 the URL wasf"{self.host}/{self.prefix}/..."and kept it. A deployment reached through a reverse proxy under a path now gets its API calls sent to the wrong place:The first attempt now uses
self.host(which keeps the path); fallback regions from/settings/regionsare still bare origins, as before.self.hostitself also had a doubled slash (https://proxy.example.com//livekit), because the path fromurlparsealready starts with/; it is nowhttps://proxy.example.com/livekit. For a URL without a path,self.hostequals the origin, so the request URL is unchanged.tests/api/test_twirp_client.pyrecords the URLrequest()posts to. The two cases with a base path fail onmainand pass with this change; the two without a path pass on both.pytest tests/api: 14 passed, 28 skipped (the failover tests need the mock server, which CI starts).ruff format --check,ruff checkandmypy livekit-api/livekitpass.Scope: failover only engages for
*.livekit.cloudhosts; region discovery (/settings/regions) and fallback attempts still use bare origins, which is unchanged.