Skip to content
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

fix: Range suffixes are not Rust RangeTo #155

Merged
merged 1 commit into from
Nov 24, 2023
Merged

Conversation

seanmonstar
Copy link
Member

An HTTP Range of bytes=-100 means a suffix, the last 100 bytes. This was wrongly parsed as the Rust range ..100, which means the first 100 bytes.

This has been fixed, but doing so required change Range::iter to accept a length argument, to determine if the ranges are satisfiable.

Closes #87

BREAKING CHANGE: Change .iter() calls to .satisfiable_ranges(len).
Also, the Range::bytes() constructor will now return an error if
pass a RangeTo (e.g. Range::bytes(..100)).

@seanmonstar
Copy link
Member Author

This waited so long because it was a breaking change, but can now be included with the http upgrade. This is a different take from #93, which doesn't expose as many new types.

It's a very conservative change, while allowing something much more comprehensive from eventually being added.

@rakshith-ravi
Copy link

Idk if you're big on tests, but if we're testing satisfiable range, then the opposite should also be tested, shouldn't it?

An HTTP Range of `bytes=-100` means a suffix, the last 100 bytes. This
was wrongly parsed as the Rust range `..100`, which means the first 100
bytes.

This has been fixed, but doing so required change `Range::iter` to
accept a length argument, to determine if the ranges are satisfiable.

BREAKING CHANGE: Change `.iter()` calls to `.satisfiable_ranges(len)`.
  Also, the `Range::bytes()` constructor will now return an error if
  pass a `RangeTo` (e.g. `Range::bytes(..100)`).
@seanmonstar seanmonstar merged commit f2c4aba into master Nov 24, 2023
8 checks passed
@seanmonstar seanmonstar deleted the range-satisfiable branch November 24, 2023 14:00
Comment on lines +69 to +72
pub fn satisfiable_ranges<'a>(
&'a self,
len: u64,
) -> impl Iterator<Item = (Bound<u64>, Bound<u64>)> + 'a {
Copy link

@DDtKey DDtKey Mar 7, 2024

Choose a reason for hiding this comment

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

Hi @seanmonstar
Thanks for these changes, but it looks like it still works not as expected

We can pass the len of the content, but for unbounded or included > len there is no usage of min(), like for example it was implemented in #93

And in general would be nice to have more validation, like from < to.

Otherwise hard to say it's "satisfiable" ranges 🤔

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.

Mapping of HTTP ranges to std::ops::Bound based ranges is faulty
4 participants