Skip to content

chore: adds Content-Range and Content-Length - #1328

Open
ErikSin wants to merge 2 commits into
mainfrom
chore-add-content-length-and-content-range-to-blob-responses
Open

chore: adds Content-Range and Content-Length#1328
ErikSin wants to merge 2 commits into
mainfrom
chore-add-content-length-and-content-range-to-blob-responses

Conversation

@ErikSin

@ErikSin ErikSin commented Sep 2, 2026

Copy link
Copy Markdown

towards 2109 in comapeo mobile

iOS uses AVPlayer (via Expo-Audio) to play audio within Comapeo-Mobile. The Audio returned by the fastify server was not playing at all.

The blob download route (GET /projects/:projectId/blob/...) never sent Content-Length, and didn't support Range requests. Without a known content length iOS's AVPlayer can't determine a video's duration and treats it as an indefinite live stream, which stalls forever instead of playing.

Adds a parseRangeHeader helper that parses a single Range: bytes=start-end header (including open-ended and suffix forms, e.g. bytes=500-, bytes=-500), the only form clients like AVPlayer send.

When a valid Range header is present, the route now reads only the requested byte span from the blob store, responds 206 Partial Content with Content-Range and Content-Length, and always advertises Accept-Ranges: bytes. Full responses now also get an explicit Content-Length.

Threads start/length through to blobStore.createReadStreamFromEntry, which already forwarded its options straight to Hyperblobs' createReadStream — just needed the JSDoc updated to declare the two new option fields.
A missing/malformed/unsatisfiable Range header falls back to serving the full resource, matching standard HTTP semantics.

@ErikSin
ErikSin requested a review from RangerMauve September 2, 2026 21:06

@RangerMauve RangerMauve left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets use https://www.npmjs.com/package/range-parser instead so we don't need to maintiain this code or worry about edge cases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants