Skip to content

feature: add HTTP Range request support for video/audio seeking #68

Description

@melvincarvalho

Summary

JSS currently doesn't support HTTP Range requests, which means video/audio seeking (skipping forward/back) doesn't work.

Current Behavior

When a client requests a byte range (e.g., seeking in a video), JSS ignores the Range header and returns the full file with status 200.

Expected Behavior

JSS should:

  1. Check for Range header in GET requests
  2. Parse byte range (e.g., bytes=1000-2000 or bytes=1000-)
  3. Return partial content with status 206 Partial Content
  4. Include proper headers:
    • Content-Range: bytes start-end/total
    • Accept-Ranges: bytes
    • Content-Length: chunksize

Use Cases

  • Video seeking - Skip to any point in a video without downloading the whole file
  • Audio seeking - Same for audio files
  • Resumable downloads - Resume interrupted large file downloads
  • Efficient streaming - Only transfer what's needed

Reference Implementation

NSS has this in lib/ldp.mjs:470-490 and lib/handlers/get.mjs:54,124-128:

// Parse range header
if (options.range) {
  const parts = options.range.replace(/bytes=/, '').split('-')
  const start = parseInt(parts[0], 10)
  const end = parts[1] ? parseInt(parts[1], 10) : total - 1
  const chunksize = (end - start) + 1
  contentRange = 'bytes ' + start + '-' + end + '/' + total
  
  // Create read stream with range
  stream = fs.createReadStream(path, { start, end })
}

// Set response headers
if (contentRange) {
  res.status(206)
  res.set({
    'Content-Range': contentRange,
    'Accept-Ranges': 'bytes',
    'Content-Length': chunksize
  })
}

Implementation Notes

For JSS with Fastify, the implementation would go in the GET handler:

  1. Check request.headers.range
  2. Use fs.createReadStream(path, { start, end }) for partial reads
  3. Set appropriate response headers and status 206

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