Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 1, 2026

Implementation Plan for Partial Static Files (HTTP Range Support)

  • Understand existing static file serving code
  • Add Range header parsing logic
  • Implement byte range calculation and validation
  • Add Accept-Ranges header to static file responses
  • Modify file streaming to support ranges with 206 status
  • Handle edge cases (invalid ranges, out of bounds, etc.)
  • Test with curl commands for Range requests
  • Verify backward compatibility (requests without Range header)
  • Address code review feedback
  • Add stream error handling
  • Eliminate code duplication in stream creation

Implementation Complete and Reviewed!

Features Added:

  • ✅ HTTP Range support for static files (PNG, PDF, JPG, etc.)
  • ✅ Three range formats supported:
    • bytes=0-999 - specific byte range
    • bytes=1000- - from byte to end of file
    • bytes=-500 - last N bytes (suffix range)
  • ✅ Returns HTTP 206 Partial Content with Content-Range header
  • ✅ Returns HTTP 416 Range Not Satisfiable for invalid ranges
  • ✅ Accept-Ranges: bytes header on all static file responses
  • ✅ Range requests only work on uncompressed files (by design)
  • ✅ HEAD requests properly ignore Range headers
  • ✅ Multi-range requests gracefully fall back to full file
  • ✅ Stream error handling to prevent crashes
  • ✅ Clean, DRY code without duplication
  • ✅ Fully backward compatible with existing functionality

Testing Results:

All test scenarios passed including:

  • Normal requests (200 OK)
  • Valid range requests (206 Partial Content)
  • Invalid ranges (416 Range Not Satisfiable)
  • Suffix ranges for last N bytes
  • Open-ended ranges (from byte to end)
  • Out-of-bounds detection
  • HEAD request handling
  • Multi-range request fallback
  • Stream error handling
Original prompt

This section details on the original issue you should resolve

<issue_title>partial static files</issue_title>
<issue_description>when serving big static files, allow sending only a range specified in header</issue_description>

<agent_instructions>Give it a try and tell me if there are bigger impediments in working with this codebase.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits January 1, 2026 18:01
- Add Range header parsing for static files
- Support three range types: start-end, start-, and -suffix
- Return 206 Partial Content with Content-Range header
- Return 416 Range Not Satisfiable for invalid ranges
- Add Accept-Ranges: bytes header to all static responses
- Only process ranges for uncompressed files (COMPRESS_METHOD_NONE)
- HEAD requests bypass Range logic as expected
- Fully backward compatible with non-Range requests

Co-authored-by: L3P3 <4629449+L3P3@users.noreply.github.com>
- Add comment clarifying only single ranges are supported (not multipart)
- Remove redundant range_start < 0 validation check
- Add error handling for file streams to prevent crashes
- Multi-range requests now gracefully fall back to full file (200 OK)

Co-authored-by: L3P3 <4629449+L3P3@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for serving partial static files Add HTTP Range header support for partial static file serving Jan 1, 2026
Copilot AI requested a review from L3P3 January 1, 2026 18:06
@L3P3
Copy link
Owner

L3P3 commented Jan 1, 2026

@copilot I dont like the code duplication after the else if (is_range_request) {. Please merge it and pass an empty object or start end object to the createReadStream like is_range_request ? {start end} : {}.

Use conditional object for createReadStream options instead of
separate if/else branches. Pass {start, end} when is_range_request
is true, otherwise pass empty object.

Co-authored-by: L3P3 <4629449+L3P3@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 1, 2026

@copilot I dont like the code duplication after the else if (is_range_request) {. Please merge it and pass an empty object or start end object to the createReadStream like is_range_request ? {start ...

Done! Merged the duplicate code paths using a conditional object is_range_request ? {start, end} : {}. This eliminates the duplication while maintaining the same functionality. Commit: 8f61134

@L3P3 L3P3 marked this pull request as ready for review January 1, 2026 18:31
@L3P3 L3P3 merged commit bc409ff into main Jan 1, 2026
2 checks passed
@L3P3 L3P3 deleted the copilot/add-range-support-static-files branch January 1, 2026 18:36
const stream = fs.createReadStream(path_real_send);
const stream = fs.createReadStream(
path_real_send,
is_range_request ? {start: range_start, end: range_end} : {}
Copy link
Contributor

Choose a reason for hiding this comment

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

why dont u send undefined? maybe a little faster?

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.

partial static files

3 participants