From 48c7b159efcc8b2784440045f3d0ae17341d0fad Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Wed, 14 Oct 2026 01:09:25 -0500 Subject: [PATCH] send a user agent of our own when downloading installers Cloudflare, in front of git.jcollie.dev, answers urllib's default `Python-urllib/3.x` user agent with a 403, so checking any installer hosted there failed. It had not shown because no change has yet asked for one to be downloaded. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01D31MsLkM9DkCauP1EB2zgw --- tools/wingetsource/check.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/wingetsource/check.py b/tools/wingetsource/check.py index 8484f6a..18d5113 100644 --- a/tools/wingetsource/check.py +++ b/tools/wingetsource/check.py @@ -160,9 +160,15 @@ def check_directory(directory: pathlib.Path, tree: pathlib.Path, validators=None return problems +# Cloudflare, in front of git.jcollie.dev, answers urllib's own user agent +# with a 403. +USER_AGENT = "wingetsource (+https://git.jcollie.dev/jeff/winget-pkgs)" + + def _download_sha256(url: str) -> bytes: digest = hashlib.sha256() - with urllib.request.urlopen(url, timeout=60) as response: + request = urllib.request.Request(url, headers={"User-Agent": USER_AGENT}) + with urllib.request.urlopen(request, timeout=60) as response: while chunk := response.read(1 << 20): digest.update(chunk) return digest.digest() -- knotmirror 0.0.1