refactor(yarn_client): use Location header verbatim, drop urljoin

YARN's 307 Location header is always a fully-qualified absolute URL.
The previous implementation used urllib.parse.urljoin to handle the
hypothetical case of a relative Location, but that's a defensive
codepath for a scenario that does not occur in practice. Drop it:

  - Remove 'from urllib.parse import urljoin'.
  - _request_following_redirects now assigns the Location value
    straight to the next request URL.
  - Update the docstring to reflect the new contract.
  - Remove the test that exercised the relative-Location path.

Full suite 246 passed (1 fewer than the previous commit, matching the
test that was removed).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Claude
2026-06-30 13:42:06 +08:00
co-authored by Claude Fable 5
parent 38ac3c33d6
commit a66991b4e3
2 changed files with 5 additions and 31 deletions
+5 -7
View File
@@ -28,7 +28,6 @@ field was designed for, but no longer requires the `yarn` CLI to interpret it.
"""
import json
from dataclasses import dataclass
from urllib.parse import urljoin
import httpx
import httpx_kerberos
@@ -159,9 +158,9 @@ def _request_following_redirects(
request lands unauthenticated and gets 401/403. Doing it ourselves
keeps the auth + verify config on every hop.
Relative `Location` values are resolved against the current request
URL. A 3xx without a `Location` header is returned as-is (the caller
will treat it as a non-2xx response and surface a clean error).
YARN always returns a fully-qualified absolute URL in `Location`, so
we use it verbatim. A 3xx without a `Location` header is treated as
a misconfigured server and raises YarnError.
"""
for hop in range(max_redirects + 1):
resp = _request(method, url, **kwargs)
@@ -172,9 +171,8 @@ def _request_following_redirects(
raise YarnError(
f"YARN {method} returned {resp.status_code} with no Location header at {url}"
)
next_url = urljoin(url, location)
logger.debug(f"YARN {method} {url} -> {resp.status_code}, following to {next_url}")
url = next_url
logger.debug(f"YARN {method} {url} -> {resp.status_code}, following to {location}")
url = location
raise YarnError(
f"YARN {method} exceeded {max_redirects} redirects (last url: {url})"
)