http-rs / surf

Fast and friendly HTTP client framework for async Rust
https://docs.rs/surf
Apache License 2.0
1.45k stars 119 forks source link

Provide AsyncSeek on body reader. #325

Open sagudev opened 2 years ago

sagudev commented 2 years ago

Currently there is no elegant way to seek through data stream, except using range headers manually. So I purpose adding AsyncSeek, that would provide seek method on body reader. The seek method would fail if response contains Accept-Ranges: none. In other cases the reader would actually send new request with appropriate Range header.

On SeekFrom::Start(x) the range header should look like Range: bytes={x}-, so the reader can read till the end of stream normally. For SeekFrom::Current(x) is similar to upper example: Range: bytes={c+x}-; where c is current stream position. For SeekFrom::End(x) we just get the last x bytes: Range: bytes=-{x}.