Last active
February 11, 2026 08:13
-
-
Save HirbodBehnam/d804a0a6292a3c0d9a329773b28762b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // A cloudflare worker that just proxies data from somewhere to you | |
| // Credits to https://github.com/TheGreatAzizi/GitHub-High-Speed-Mirror | |
| export default { | |
| async fetch(request, env, ctx) { | |
| // Parse the URL | |
| const url = new URL(request.url); | |
| const params = new URLSearchParams(url.search); | |
| if (!params.has("url")) return new Response("Invalid URL", { status: 400 }); | |
| const target = params.get("url"); | |
| // Request the URL | |
| const upstreamReq = new Request(target, { | |
| method: request.method, | |
| headers: { | |
| "User-Agent": "CF-Proxy", | |
| "Range": request.headers.get("Range") || "" | |
| }, | |
| redirect: "follow" | |
| }); | |
| const upstreamRes = await fetch(upstreamReq); | |
| // Stream back data | |
| const headers = new Headers(upstreamRes.headers); | |
| headers.set("Access-Control-Allow-Origin", "*"); | |
| headers.set("X-Worker-Cache", "MISS"); | |
| headers.set( | |
| "Content-Disposition", | |
| `attachment; filename="${getFilename(target, upstreamRes)}"` | |
| ); | |
| return new Response(upstreamRes.body, { | |
| status: upstreamRes.status, | |
| headers | |
| }); | |
| } | |
| }; | |
| function getFilename(url, res) { | |
| const cd = res.headers.get("content-disposition"); | |
| if (cd) { | |
| const m = cd.match(/filename="?([^"]+)"?/i); | |
| if (m) return m[1]; | |
| } | |
| return url.split("/").pop() || "download"; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment