Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions _worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ let hub_host = 'registry-1.docker.io';
// Docker认证服务器地址
const auth_url = 'https://auth.docker.io';

const FREE_DOMAINS = [
'r2.cloudflarestorage.com',
];

let 屏蔽爬虫UA = ['netcraft'];

// 根据主机名选择对应的上游地址
Expand Down Expand Up @@ -482,8 +486,19 @@ export default {
// 处理重定向
if (new_response_headers.get("Location")) {
const location = new_response_headers.get("Location");
console.info(`Found redirection location, redirecting to ${location}`);
return httpHandler(request, location, hub_host);
console.info(`Found redirection location ${location}`);
let freeDomain = false;
for (const domain of FREE_DOMAINS) {
if (location.match('\\b' + domain + '\\b')) {
freeDomain = true;
console.log(`Free domain ${domain}, redirect as is.`);
break;
}
}
if (!freeDomain) {
console.log('Not free domain, re-executing...');
return httpHandler(request, location, hub_host);
}
}

// 返回修改后的响应
Expand Down