Skip to content

Commit 3c308a9

Browse files
authored
Redirect libtorch zip downloads to download-r2.pytorch.org (#8021)
## Summary - Adds a 301 redirect in the `pep503_whl_redirect` CloudFront Function so that any request for a `/libtorch/**/*.zip` artifact on `download.pytorch.org` is redirected to the equivalent path on `download-r2.pytorch.org`. - Index pages and folder listings under `/libtorch/` continue to be served from the original origin — only the actual download artifacts shift to R2. - Example: `https://download.pytorch.org/libtorch/cpu/libtorch-shared-with-deps-2.11.0+cpu.zip` → `https://download-r2.pytorch.org/libtorch/cpu/libtorch-shared-with-deps-2.11.0+cpu.zip`. ## Test plan - [ ] Validate function syntax with `aws cloudfront test-function` against a sample `/libtorch/cpu/libtorch-shared-with-deps-2.11.0+cpu.zip` event and confirm a 301 with the expected `location` header. - [ ] Test a folder-style URI (e.g. `/libtorch/cpu`) and confirm it still rewrites to `/libtorch/cpu/index.html` (no redirect). - [ ] Test a trailing-slash URI (e.g. `/libtorch/`) and confirm it still rewrites to `/libtorch/index.html` (no redirect). - [ ] Test a `/whl/...` request and confirm behavior is unchanged. - [ ] After deploy + publish, curl a real libtorch zip URL and confirm the 301 lands at `download-r2.pytorch.org` and the file downloads successfully.
1 parent 5d787cb commit 3c308a9

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

aws/websites/download.pytorch.org/pep503_whl_redirect.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ function handler(event) {
2121

2222
// Similar behavior for libtorch
2323
if (uri.startsWith('/libtorch')) {
24+
// Redirect libtorch downloads (.zip files) to R2
25+
if (last_uri_part.endsWith('.zip')) {
26+
return {
27+
statusCode: 301,
28+
statusDescription: 'new download.pytorch.org mirror',
29+
headers: {
30+
'location': { value: 'https://download-r2.pytorch.org' + uri }
31+
}
32+
};
33+
}
2434
// Check whether the URI is missing a file name.
2535
if (uri.endsWith('/')) {
2636
request.uri += 'index.html';

0 commit comments

Comments
 (0)