oak
oak copied to clipboard
Using Range headers for more than just bytes
Hi all!
This is a feature request.
As an API designer and Oak user, I was looking for the HTTP Range header support in Oak and was pleased to see it is actually supported... with some limitation: it can only accept bytes ranges, as cruelly written in the parseRange
function in range.ts
:
if (unit !== "bytes") {
throw createHttpError(Status.RequestedRangeNotSatisfiable);
}
However the RFC is a bit less limiting on this particular subject (see https://datatracker.ietf.org/doc/html/rfc9110/#section-14.1) as it notes "Range units are intended to be extensible". I often use "items" and "pages" units myself for example.
I'm not a particularly talented Typescript developer but it doesn't seem to be such a big deal to implement and if we could agree on the approach, I could surely help.
We could introduce a GenericRange
interface that ByteRange
could extend, and update parseRange
to return either GenericRange[]
or ByteRange[]
, using the same condition you used to throw the exception. The rest of the code could be left untouched, to start.
Thank you for reading!