-
-
Notifications
You must be signed in to change notification settings - Fork 592
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(serve-static): "206 Partial Content" support #3461
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3461 +/- ##
==========================================
- Coverage 95.58% 95.36% -0.22%
==========================================
Files 155 155
Lines 9357 9524 +167
Branches 2746 2776 +30
==========================================
+ Hits 8944 9083 +139
- Misses 413 441 +28 ☔ View full report in Codecov by Sentry. |
d29d1e9
to
5802d0d
Compare
5802d0d
to
07b6334
Compare
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.
Note) ?
is added because when serve-static
checks Range
header, headers
is undefined
on some existing test cases.
Hi @exoego I'm sorry I can't review it yet. Still a little bit busy; please wait. |
I'm sorry for being super late. I have an idea, and I'll share it with you soon. |
Closes #3324
This implements 206 Partial Content(also called as range requests) support in
serve-static
middleware.It will be useful specially for seeking a video file.
serve-static
base implementation now accepts an optional function:If
partialContentSupport
is provided and HTTP header includes validRange
,serve-static
returns subsets of content.getPartialContent
function encapsulates a file handle to avoid opening and closing file multiple times.close
function is invoked when all ranges are read, to teardown the file handle.416 Range Not Satisfiable
The implementation also returns 416 Range Not Satisfiable if
Range
headers contains many range requests (more than 10), that is potentially DoS (Denial of Service) attack.This limitation (
10
) is just a clueless number.The number may be changed when we understand it is too small/too big.
Not included
If-Range
,ETag
and so on. I think this feature is useful without having cache-control, which needs a lot work.serverStatic
implementation 😭 It is solely implemented here: https://github.com/honojs/node-server/blob/74e86a28f375e5acd52e342519ff2b1110a95c16/src/serve-static.ts#L59The author should do the following, if applicable
bun run format:fix && bun run lint:fix
to format the code