Add support for byte-range requests #62
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Eleventy Dev Server does not currently support byte-range requests, which causes locally served video files to fail on Safari and all iOS browsers.
This PR adds support for byte-range requests, so local video files load correctly from partial byte-range requests. This fixes #51.
Rather than trying to implement a new byte-range handler, I suggest the using the send library from PillarJS. This project already relies on their finalhandler library. These two libraries each log about 25M downloads per week.
I recognize, respect and appreciate the desire to keep 11ty's installations small. Send has 13 dependencies, 7 of which are already utilized and installed by eleventy-dev-server.
With
send
, byte-range requests can be implemented by simply adding a range-header check toeleventyProjectMiddleware
:Tests
The
fetchHeadersForRequest
test helper function was slightly modified. It now accepts anextras
argument, which can be used to add additional http.request options. This allows the new tests to include arange
header. The function's "Invalid status code" error-check was also modified to recognize success codes200
and206
.Changes to the tests were checked and verified before adding range-requests to server.js, all tests passed.
Two tests specific to this change were added. The first validates byte-range headers are returned correctly, the second assures byte-range headers do not appear on normal requests.
Also note that
options.portReassignmentRetryCount
was increased to prevent the test suite from running out of ports.