Skip to content

Commit dfac79d

Browse files
committed
Handle dockerhub blob redirect
1 parent e176bc4 commit dfac79d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,22 @@ async function handleRequest(request) {
105105
const newReq = new Request(newUrl, {
106106
method: request.method,
107107
headers: request.headers,
108-
redirect: "manual",
108+
// don't follow redirect to dockerhub blob upstream
109+
redirect: isDockerHub ? "manual" : "follow",
109110
});
110111
const resp = await fetch(newReq);
111112
if (resp.status == 401) {
112113
return responseUnauthorized(url);
113114
}
115+
// handle dockerhub blob redirect manually
116+
if (isDockerHub && resp.status == 307) {
117+
const location = new URL(resp.headers.get("Location"));
118+
const redirectResp = await fetch(location.toString(), {
119+
method: "GET",
120+
redirect: "follow",
121+
});
122+
return redirectResp;
123+
}
114124
return resp;
115125
}
116126

0 commit comments

Comments
 (0)