-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add maxChunkSize
option
#90
base: master
Are you sure you want to change the base?
Conversation
types/index.d.ts
Outdated
/** | ||
* Limit max response size when acceptRanges is true, defaults to the entire file size. | ||
*/ | ||
maxChunkSize?: number | undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add a test for this type? We used tsd.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review. I added tsd
tests for maxChunkSize
and acceptRanges
.
Could you take another look?
Is a maxChunkSize not basically a highWatermark? Should we name it like that? |
I don't think that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 6 out of 6 changed files in this pull request and generated no suggestions.
Comments skipped due to low confidence (2)
test/utils.js:12
- The function name should be 'shouldHaveHeader' instead of 'shouldNotHaveHeader'.
module.exports.shouldHaveHeader = function shouldNotHaveHeader (header, t) {
README.md:52
- The heading should be 'maxChunkSize' instead of 'acceptRanges'.
##### acceptRanges
README.md
Outdated
##### acceptRanges | ||
|
||
Specify maximum chunk size, defaults to send the entire file size. | ||
This will be used when `acceptRanges` is true. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be renamed to maxChunkSize
and moved to be after maxAge
, as the options are sorted alphabetically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I also re-order the option in other files.
maxChunkSize
option to SendOptions
maxChunkSize
option
Co-authored-by: Frazer Smith <[email protected]> Signed-off-by: Kaede Fujisaki <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the review and typo suggestion!
Could you take another look?
README.md
Outdated
##### acceptRanges | ||
|
||
Specify maximum chunk size, defaults to send the entire file size. | ||
This will be used when `acceptRanges` is true. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I also re-order the option in other files.
const root = options.root | ||
? resolve(options.root) | ||
: null | ||
|
||
return { | ||
acceptRanges, | ||
maxChunkSize, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry @ledyba, could you also move this to be in alphabetical order as well please?
The name is not that nice. maxChunkSize is imho a |
@@ -546,6 +551,9 @@ function sendFileDirectly (request, path, stat, options) { | |||
|
|||
// Content-Range | |||
statusCode = 206 | |||
if (options.maxChunkSize) { | |||
ranges[0].end = Math.min(ranges[0].end, ranges[0].start + options.maxChunkSize - 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesnt seem right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
preemptive blocker
Currently, this library tends to send entire file when
'acceptRanges': true,
In this PR, I added
maxChunkSize
tosend.SendOptions
to limit the max chunk size.Test case: https://hexe.net/2022/09/17/17:04:55/
Souce code is here
I'm using firefox 132.0.
Request:
Response:
I also checked in MS Edge 131.0.2903.51.
Checklist
npm run test
andnpm run benchmark
npm run benchmark
commandand the Code of conduct