hyperium / headers

Typed HTTP Headers from hyper
https://hyper.rs
MIT License
162 stars 84 forks source link

fix: Range suffixes are not Rust RangeTo #155

Closed seanmonstar closed 9 months ago

seanmonstar commented 9 months ago

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 commented 9 months ago

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 commented 9 months ago

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