Skip to content

fix(gateway): support suffix range requests #922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

aschmahmann
Copy link
Contributor

@aschmahmann aschmahmann commented May 22, 2025

fixes ipfs/kubo#10808

Well ... the need for this PR is quite embarrassing. I thought we had this covered in gateway conformance but we don't.

@lidel IIRC we discussed this when this code path was implemented and maybe this was just supposed to not support suffix requests and return 200 with everything instead of 206 (as we do for ranges on things like dir-index-html responses), but given we found a user who could actually benefit from it it seemed reasonable to implement. Feel free to take over the PR and change as you wish, but figured I'd at least present an option to help get things moving.

  • Figure out how we want to resolve this
  • Add gateway conformance tests

@aschmahmann aschmahmann requested a review from lidel as a code owner May 22, 2025 01:23
@@ -219,10 +219,11 @@ type ContentPathMetadata struct {
// - From >= 0 and To = nil: Get the file (From, Length)
// - From >= 0 and To >= 0: Get the range (From, To)
// - From >= 0 and To <0: Get the range (From, Length - To)
// - From < 0 and To = nil: Get the file (Length - From, Length)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lidel the rules for this struct were not great from the get go. There's a similar struct that's more expansive (

boxo/gateway/gateway.go

Lines 98 to 108 in 2f225c4

// DagByteRange describes a range request within a UnixFS file. "From" and
// "To" mostly follow the [HTTP Byte Range] Request semantics:
//
// - From >= 0 and To = nil: Get the file (From, Length)
// - From >= 0 and To >= 0: Get the range (From, To)
// - From >= 0 and To <0: Get the range (From, Length - To)
// - From < 0 and To = nil: Get the file (Length - From, Length)
// - From < 0 and To >= 0: Get the range (Length - From, To)
// - From < 0 and To <0: Get the range (Length - From, Length - To)
//
// [HTTP Byte Range]: https://httpwg.org/specs/rfc9110.html#rfc.section.14.1.2
) that exists because the trustless-gateway entity-bytes spec is a little more flexible than the HTTP range requests spec. In theory this struct differed because its rules were supposed to be for just HTTP ... but rule 3 was never implemented correctly / doesn't represent suffix-requests.

Some options look like:

  1. Add a 4th rule that is the suffix requests (what's done here)
  2. Replace the 3rd rule with one proper for suffix requests (in theory even doable without changing the struct types) ... technically a breaking change although I suspect this isn't much used externally
  3. Just combine this with DagBytesRange and have a single struct

Copy link
Member

Choose a reason for hiding this comment

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

option (1) sgtm – seems to be enough to fix ipfs/kubo#10808 and pass all new tests added in ipfs/gateway-conformance#213

@@ -475,9 +475,18 @@ func (i *handler) seekToStartOfFirstRange(w http.ResponseWriter, r *http.Request
return true
}

func seekToRangeStart(data io.Seeker, ra *ByteRange) error {
func seekToRangeStart(data io.Seeker, ra *ByteRange, size int64) error {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should figure out how much testing is worth doing here vs just adding to gateway conformance and relying on that.

It's notable that there was a TODO around testing this area 🤦 https://github.com/ipfs/boxo/pull/922/files#diff-5b9dda4053dba85f902d2464389f79cdfca0976873fd206acaefcb09784d6e98R55, let's drop that TODO and replace with enough testing that we're happy 😅.

Copy link
Member

Choose a reason for hiding this comment

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

Dropped todo + added e2e tests to ipfs/gateway-conformance#213, this way the same tests will be applied to inbrowser.link.

@lidel lidel changed the title fix(gateway): support suffix requests fix(gateway): support suffix range requests May 27, 2025
@lidel
Copy link
Member

lidel commented May 27, 2025

Triage notes:

@lidel lidel requested a review from a team as a code owner May 27, 2025 22:05
@lidel lidel force-pushed the fix/range-suffix branch from 6f9fbe9 to c30b27a Compare May 27, 2025 22:23
@lidel lidel force-pushed the fix/range-suffix branch from e5f8c09 to ee5383d Compare May 27, 2025 23:34
lidel added 2 commits May 28, 2025 01:42
car backend did not support negative ranges, this attempts to fix that
for raw blocks and dag-pb files
@lidel lidel force-pushed the fix/range-suffix branch from cc1dde9 to 6274fc5 Compare May 28, 2025 00:29
@lidel
Copy link
Member

lidel commented May 28, 2025

I will take a look with fresh eyes tomorrow, remaining work is to bubble up and land everything:

  • release gateway-conformance (with changelog)
  • update this PR to use latest gateway-conformace and merge
  • update kubo in fix: boxo#922 kubo#10818 to use latest boxo main + released gateway conformance

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.

Negative range requests are not implemented correctly
2 participants