forked from GitHub/cloudflare-docker-proxy
Handle dockerhub blob redirect
This commit is contained in:
12
src/index.js
12
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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user