Merge pull request #32921 from BerriAI/litellm_lit4126_default_port_strip

fix(mcp): strip scheme default port from get_request_base_url netloc
This commit is contained in:
tin-berri 2026-07-11 11:19:30 -07:00 committed by GitHub
commit 9659ae2f40
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 36 additions and 1 deletions

View file

@ -129,7 +129,7 @@ def get_request_base_url(request: Request) -> str:
if x_forwarded_port and ":" not in netloc:
netloc = f"{netloc}:{x_forwarded_port}"
return urlunparse((scheme, netloc, parsed.path, "", "", ""))
return urlunparse((scheme, _strip_default_port(scheme, netloc), parsed.path, "", "", ""))
def validate_loopback_redirect_uri(redirect_uri: str) -> None:

View file

@ -1848,6 +1848,41 @@ async def test_token_endpoint_respects_x_forwarded_host():
None,
"https://external.com",
),
(
"http://localhost:4000/",
"https",
"proxy.example.com",
"443",
"https://proxy.example.com",
),
(
"http://localhost:4000/",
"http",
"proxy.example.com",
"80",
"http://proxy.example.com",
),
(
"http://internal.local/",
"https",
None,
"443",
"https://internal.local",
),
(
"http://localhost:4000/",
"https",
"proxy.example.com",
"8443",
"https://proxy.example.com:8443",
),
(
"http://localhost:4000/",
"https",
"proxy.example.com:443",
None,
"https://proxy.example.com",
),
],
)
def test_get_request_base_url_comprehensive(