Skip to content

fix(api): keep the base path of the server URL in Twirp requests - #861

Merged
lukasIO merged 1 commit into
livekit:mainfrom
ANDROIDHASSAN:fix/twirp-keep-base-path
Oct 14, 2026
Merged

lukasIO merged 1 commit into
livekit:mainfrom
ANDROIDHASSAN:fix/twirp-keep-base-path

Conversation

@ANDROIDHASSAN

Copy link
Copy Markdown
Contributor

Since the region-failover change (#733), TwirpClient.request builds every request URL from self._origin, which is scheme://host[:port] only, so a base path in the server URL is dropped. Before #733 the URL was f"{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:

LiveKitAPI(url="https://proxy.example.com/livekit", ...)
# requests go to https://proxy.example.com/twirp/livekit.RoomService/ListRooms
# expected       https://proxy.example.com/livekit/twirp/livekit.RoomService/ListRooms

The first attempt now uses self.host (which keeps the path); fallback regions from /settings/regions are still bare origins, as before. self.host itself also had a doubled slash (https://proxy.example.com//livekit), because the path from urlparse already starts with /; it is now https://proxy.example.com/livekit. For a URL without a path, self.host equals the origin, so the request URL is unchanged.

tests/api/test_twirp_client.py records the URL request() posts to. The two cases with a base path fail on main and 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 check and mypy livekit-api/livekit pass.

Scope: failover only engages for *.livekit.cloud hosts; region discovery (/settings/regions) and fallback attempts still use bare origins, which is unchanged.

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.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@lukasIO lukasIO left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@lukasIO
lukasIO merged commit d5b847c into livekit:main Oct 14, 2026
23 checks passed
@ANDROIDHASSAN
ANDROIDHASSAN deleted the fix/twirp-keep-base-path branch October 14, 2026 14:23
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