Set a User-Agent for package archive downloads (#52177)

Send `User-Agent: codex-package` when downloading archives in
`scripts/codex_package/dotslash.py`.

GitOrigin-RevId: b12dc962b28d795704ba780b020fbf7ab91f5d50
This commit is contained in:
Michael Bolin
2026-10-08 17:11:45 +00:00
committed by copyberry
parent 6f6e80bcdd
commit bc1f22455d
+3 -2
View File
@@ -11,7 +11,7 @@ import zipfile
from dataclasses import dataclass
from pathlib import Path
from urllib.parse import urlparse
from urllib.request import urlopen
from urllib.request import Request, urlopen
from .targets import TargetSpec
@@ -168,7 +168,8 @@ def download_archive(url: str, archive_path: Path) -> None:
temp_path = archive_path.with_suffix(f"{archive_path.suffix}.tmp")
temp_path.unlink(missing_ok=True)
try:
with urlopen(url, timeout=DOWNLOAD_TIMEOUT_SECS) as response:
request = Request(url, headers={"User-Agent": "codex-package"})
with urlopen(request, timeout=DOWNLOAD_TIMEOUT_SECS) as response:
with open(temp_path, "wb") as out:
shutil.copyfileobj(response, out)
temp_path.replace(archive_path)