Skip to content

Using Range headers for more than just bytes #623

@mrjoops

Description

@mrjoops

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions