From 47001590eb15626525476fdd77469e3a2a28fe5a Mon Sep 17 00:00:00 2001 From: Yisheng Cai Date: Mon, 17 Feb 2025 02:30:59 +0800 Subject: [PATCH 1/3] Change redirect mode from follow to manual (#104) --- src/index.js | 2 +- wrangler.toml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 785a41aae..7c4ebd8d1 100644 --- a/src/index.js +++ b/src/index.js @@ -105,7 +105,7 @@ async function handleRequest(request) { const newReq = new Request(newUrl, { method: request.method, headers: request.headers, - redirect: "follow", + redirect: "manual", }); const resp = await fetch(newReq); if (resp.status == 401) { diff --git a/wrangler.toml b/wrangler.toml index b245b957a..bbf4845d2 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -12,6 +12,7 @@ CUSTOM_DOMAIN = "libcuda.so" [env.dev.vars] MODE = "debug" TARGET_UPSTREAM = "https://registry-1.docker.io" +CUSTOM_DOMAIN = "exmaple.com" [env.production] name = "cloudflare-docker-proxy" From e176bc4b29d3e44554463c03f3411f191d48be9a Mon Sep 17 00:00:00 2001 From: ciiiii Date: Sun, 16 Feb 2025 12:35:01 -0600 Subject: [PATCH 2/3] Remove stage deployment --- .github/workflows/stage.yaml | 25 ------------------------- 1 file changed, 25 deletions(-) delete mode 100644 .github/workflows/stage.yaml diff --git a/.github/workflows/stage.yaml b/.github/workflows/stage.yaml deleted file mode 100644 index 1cd233ca2..000000000 --- a/.github/workflows/stage.yaml +++ /dev/null @@ -1,25 +0,0 @@ -name: Deploy to Cloudflare Workers(Staging) - -on: - pull_request_target: - paths-ignore: - - '**.md' - repository_dispatch: - -jobs: - build-and-deploy: - runs-on: ubuntu-latest - name: Build & Deploy - steps: - - uses: actions/checkout@v4 - - name: Publish - uses: cloudflare/wrangler-action@v3 - env: - CUSTOM_DOMAIN: ${{ secrets.CUSTOM_DOMAIN || 'libcuda.so' }} - with: - apiToken: ${{ secrets.CF_API_TOKEN }} - accountId: ${{secrets.CF_ACCOUNT_ID}} - vars: - CUSTOM_DOMAIN - command: deploy --env staging --minify src/index.js - environment: staging \ No newline at end of file From dfac79db55e93267e27d5b9ff557e8068f425060 Mon Sep 17 00:00:00 2001 From: ciiiii Date: Sun, 16 Feb 2025 18:14:20 -0600 Subject: [PATCH 3/3] 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 7c4ebd8d1..a97a73819 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; }