zio-http icon indicating copy to clipboard operation
zio-http copied to clipboard

Support Http Range header on request for Files

Open ashprakasan opened this issue 4 years ago • 22 comments

Is your feature request related to a problem? Please describe.

The Range HTTP request header indicates the part of a document that the server should return. Several parts can be requested with one Range header at once, and the server may send back these ranges in a multipart document.

Describe the solution you'd like

Example requesting 3 ranges from files - Range: bytes=200-1000, 2000-6576, 19000-

Send only those parts of the document in Response.

Describe alternatives you've considered

Currently, the range is hardcoded as follows - ctx.write(new DefaultFileRegion(raf.getChannel, 0, fileLength)) Manipulate the positions as per request headers instead.

Additional context

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Range

ashprakasan avatar Dec 28 '21 08:12 ashprakasan

/bounty $250

jdegoes avatar Oct 08 '25 15:10 jdegoes

@jdegoes Does all zio bounties are reserved to @987Nabil?

BenraouaneSoufiane avatar Oct 08 '25 15:10 BenraouaneSoufiane

/attempt #709

jxnnyo avatar Oct 28 '25 21:10 jxnnyo

/attempt #709

SandyUndefined avatar Dec 11 '25 06:12 SandyUndefined

/attempt #709 I'm gonna modify the Handler.scala and Body.scala to create a response from a file

francoo98 avatar Dec 14 '25 21:12 francoo98

/attempt #709

Exceluyi avatar Dec 27 '25 04:12 Exceluyi

/attempt #709

Implementation Plan

I'll implement HTTP Range request support (RFC 7233) with the following approach:

  1. Create Range Parser (zio/http/headers/Range.scala) - Parse Range: bytes= headers into typed models supporting single ranges (bytes=0-499), suffix ranges (bytes=-500), and multiple ranges (bytes=0-499,1000-1499)

  2. Create RangeSupport Handler (zio/http/RangeSupport.scala) - Core logic to:

    • Detect Range header in requests
    • Validate ranges against file size
    • Return 206 Partial Content with Content-Range for single ranges
    • Return 206 with multipart/byteranges for multiple ranges
    • Return 416 Range Not Satisfiable for invalid ranges
  3. Add Header Types - Define Range, Content-Range, and Accept-Ranges headers in the headers package

  4. Replace DefaultFileRegion - Update existing file serving code to use RangeSupport.serveFile() instead of hardcoded DefaultFileRegion(raf.getChannel, 0, fileLength)

  5. Add Tests - Comprehensive test suite covering all range types, error cases, and multipart responses

This enables features like video seeking, resume downloads, and parallel chunk fetching while maintaining backward compatibility (requests without Range headers get full file with 200 OK).

ritik4ever avatar Dec 27 '25 14:12 ritik4ever

Hey, apologies for jumping the process. This is my first bounty attempt and I got ahead of myself. I should have posted /attempt #709 with my plan before submitting the PR!

That said, PR #3889 is fully green and implements the complete RFC 9110 Range spec: single ranges, multi-ranges (multipart/byteranges), suffix ranges, If-Range/ETag validation, and >2GB file support. Demo GIF is in the PR.

Happy to address any feedback. Will follow the process properly next time!

Michael-A-Kuykendall avatar Jan 16 '26 07:01 Michael-A-Kuykendall

🎉🎈 @987Nabil has been awarded $250 by ZIO! 🎈🎊

algora-pbc[bot] avatar Jan 18 '26 08:01 algora-pbc[bot]

Excuse me

Michael-A-Kuykendall avatar Jan 18 '26 10:01 Michael-A-Kuykendall

Hope this doesn't mean someone else earned my claimed bounty?

Michael-A-Kuykendall avatar Jan 18 '26 10:01 Michael-A-Kuykendall

@987Nabil how is your forks solutionmaterially different from my solution?

Why wasn't I awarded the bounty?

Michael-A-Kuykendall avatar Jan 18 '26 11:01 Michael-A-Kuykendall

@Michael-A-Kuykendall Sorry, taking a look again at your PR, it actually did not look that bad. Please forgive me, I took a look at some of the other PRs for this issue and also many other PRs in the zio org that where garbage and might have been a little biased when I took a look. What I can offer you is, that if you find an open issue or bug you would like to fix, even without bounty, I can get you an exclusive bounty. Best would be you ping me on Discord if you are interested.

987Nabil avatar Jan 18 '26 11:01 987Nabil

I will run this past Algora and see what they say about users creating bounties, waiting until someone does the work, then stealing a PR and my clear bounty.

Michael-A-Kuykendall avatar Jan 18 '26 14:01 Michael-A-Kuykendall

This was just theft, plain and simple.

Michael-A-Kuykendall avatar Jan 18 '26 14:01 Michael-A-Kuykendall

@Michael-A-Kuykendall Sorry, taking a look again at your PR, it actually did not look that bad. Please forgive me, I took a look at some of the other PRs for this issue and also many other PRs in the zio org that where garbage and might have been a little biased when I took a look. What I can offer you is, that if you find an open issue or bug you would like to fix, even without bounty, I can get you an exclusive bounty. Best would be you ping me on Discord if you are interested.

I'll not be doing further work for Zio to steal again, thx

Michael-A-Kuykendall avatar Jan 18 '26 14:01 Michael-A-Kuykendall

Let's be perfectly clear; you took (stole completely) one PR and got the bounty yourself, and canceled my other PR without really checking it correctly.

Did I read this series of events correctly?

Michael-A-Kuykendall avatar Jan 18 '26 14:01 Michael-A-Kuykendall

From what I can see, I did the work, the maintainer accepted it and claimed the bounty

Image

Michael-A-Kuykendall avatar Jan 18 '26 16:01 Michael-A-Kuykendall

Last protest comment: @987Nabil clearly took my fork and claimed it for bounty. Love to have this ethically resolved.

Michael-A-Kuykendall avatar Jan 18 '26 17:01 Michael-A-Kuykendall

Timeline: Jan 16, 01:21:15Z - I create PR #3889 (complete implementation, green CI, demo GIF) Jan 17, 21:02:12Z - 987Nabil creates PR #3897 (1.75 days LATER) Jan 18, 08:41:39Z - 987Nabil's PR gets MERGED Jan 18 - Your PR #3889 gets CLOSED with comment "Already on master"

The Maintainer Privilege Abuse: 987Nabil was ASSIGNED to issue #709 from the beginning (maintainer/contributor status)

He had direct access to reviewers (jdegoes, kyri-petrou, vigoo)

His PR got fast-tracked despite being submitted 1.75 days after mine

My complete, working PR was dismissed as "Already on master" From the issue comments, 987Nabil admitted: "I did not even take a look at your PR before I opened mine. I did not steal anything."

Michael-A-Kuykendall avatar Jan 18 '26 18:01 Michael-A-Kuykendall