From dfac79db55e93267e27d5b9ff557e8068f425060 Mon Sep 17 00:00:00 2001 From: ciiiii Date: Sun, 16 Feb 2025 18:14:20 -0600 Subject: [PATCH] Handle dockerhub blob redirect --- src/index.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 7c4ebd8..a97a738 100644 --- a/src/index.js +++ b/src/index.js @@ -105,12 +105,22 @@ async function handleRequest(request) { const newReq = new Request(newUrl, { method: request.method, headers: request.headers, - redirect: "manual", + // don't follow redirect to dockerhub blob upstream + redirect: isDockerHub ? "manual" : "follow", }); const resp = await fetch(newReq); if (resp.status == 401) { return responseUnauthorized(url); } + // handle dockerhub blob redirect manually + if (isDockerHub && resp.status == 307) { + const location = new URL(resp.headers.get("Location")); + const redirectResp = await fetch(location.toString(), { + method: "GET", + redirect: "follow", + }); + return redirectResp; + } return resp; }