feat(server): support static asset byte ranges#2711
Conversation
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e5271927a5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const timestamp = Date.parse(trimmed); | ||
| return Number.isFinite(timestamp) && Math.floor(mtimeMs / 1000) * 1000 <= timestamp; |
There was a problem hiding this comment.
Reject non-HTTP dates before honoring If-Range
If-Range only permits an HTTP-date, but Date.parse() also accepts formats such as 12/31/2099 and 2099-12-31. A client resuming an older download with such an invalid future validator will therefore receive 206 bytes from the current file instead of the required full 200 response, potentially combining bytes from different file versions. Validate the HTTP-date grammar before comparing the timestamp.
Useful? React with 👍 / 👎.
Performance benchmarksCompared 0 improved · 0 regressed · 6 within ±1.5%
View detailed results and traces 🟢 improvement · 🔴 regression · ⚫ change below 1.5% · paired base/head |
3988cd5 to
4db2e69
Compare
What changed
bytesranges in the Node production static server206 Partial Contentand416 Range Not SatisfiableresponsesIf-RangevalidationAccept-Rangesand emitLast-ModifiedWhy
The Node production server ignored
Range, unlike Next.js static serving. Large emitted media and other static assets could only be downloaded in full, preventing efficient seeking and resumable transfers.Impact
Node deployments can serve bounded, open-ended, and suffix byte ranges.
HEADcontinues to ignoreRangeas required by RFC 9110, and normal compression behavior is unchanged for non-range requests.Validation
vp test run tests/http-range.test.ts tests/static-file-cache.test.tsvp test run tests/app-router-production-server.test.ts -t "serves static asset byte ranges"vp check tests/http-range.test.ts tests/static-file-cache.test.ts tests/app-router-production-server.test.ts packages/vinext/src/server/http-range.ts packages/vinext/src/server/static-file-cache.ts packages/vinext/src/server/prod-server.ts