Skip to content

Commit

Permalink
Add chapter with supported HTTP clients
Browse files Browse the repository at this point in the history
  • Loading branch information
pka committed Aug 31, 2023
1 parent 4770522 commit d0b14b3
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## (UNRELEASED)

* Add ureq client support
* Return UnexpectedEof when read causes HTTP error 416

## 0.7.0 (2023-08-31)

* Add sync API with blocking::reqwest
Expand Down
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
[![crates.io version](https://img.shields.io/crates/v/http-range-client.svg)](https://crates.io/crates/http-range-client)
[![docs.rs docs](https://docs.rs/http-range-client/badge.svg)](https://docs.rs/http-range-client)

HTTP client for HTTP Range requests with a buffer optimized for sequential requests.
HTTP client for HTTP Range requests with a buffer optimized for sequential reading.

Implements Seek+Read for blocking clients, which makes it a drop-in replacement for local files.

Usage examples:
## Usage examples

use http_range_client::*;

Expand All @@ -23,3 +23,13 @@ Usage examples:
let mut bytes = [0; 3];
reader.read_exact(&mut bytes)?;
assert_eq!(&bytes, b"PNG");

## Supported HTTP clients (feature flag)

* [reqwest](https://crates.io/crates/reqwest) async (`reqwest-async`, default)
* [reqwest](https://crates.io/crates/reqwest) blocking (`reqwest-sync`, default)
Not supported on Wasm target
* [ureq](https://crates.io/crates/ureq) blocking (`ureq-sync`)
Supports native and Wasm target

Other clients can be used via the `AsyncBufferedHttpRangeClient` resp. `SyncBufferedHttpRangeClient` adapter, after implementing the `AsyncHttpRangeClient` resp. `SyncHttpRangeClient` trait.
5 changes: 2 additions & 3 deletions src/buffered_range_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub(crate) mod nonblocking {
use super::*;
use crate::range_client::AsyncHttpRangeClient;

/// HTTP client adapter for HTTP Range requests with a buffer optimized for sequential requests
/// HTTP client adapter for HTTP Range requests with a buffer optimized for sequential reading
pub struct AsyncBufferedHttpRangeClient<T: AsyncHttpRangeClient> {
http_client: T,
url: String,
Expand Down Expand Up @@ -155,7 +155,7 @@ pub(crate) mod sync {
use bytes::Buf;
use std::io::{Read, Seek, SeekFrom};

/// HTTP client adapter for HTTP Range requests with a buffer optimized for sequential requests
/// HTTP client adapter for HTTP Range requests with a buffer optimized for sequential reading
pub struct SyncBufferedHttpRangeClient<T: SyncHttpRangeClient> {
http_client: T,
url: String,
Expand Down Expand Up @@ -226,7 +226,6 @@ pub(crate) mod sync {
}
e => std::io::Error::new(std::io::ErrorKind::Other, e.to_string()),
})?;
// TODO: return for HTTP status 416
bytes.copy_to_slice(&mut buf[0..bytes.len()]);
Ok(length)
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! HTTP client for HTTP Range requests with a buffer optimized for sequential requests.
//! HTTP client for HTTP Range requests with a buffer optimized for sequential reading.

//! ## Usage example
//!
Expand Down
4 changes: 2 additions & 2 deletions src/reqwest_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub(crate) mod nonblocking {
}
}

/// Async HTTP client for HTTP Range requests with a buffer optimized for sequential requests.
/// Async HTTP client for HTTP Range requests with a buffer optimized for sequential reading.
pub type BufferedHttpRangeClient = crate::AsyncBufferedHttpRangeClient<reqwest::Client>;

impl BufferedHttpRangeClient {
Expand Down Expand Up @@ -75,7 +75,7 @@ pub(crate) mod sync {
}
}

/// Sync HTTP client for HTTP Range requests with a buffer optimized for sequential requests.
/// Sync HTTP client for HTTP Range requests with a buffer optimized for sequential reading.
pub type HttpReader = crate::SyncBufferedHttpRangeClient<reqwest::blocking::Client>;

impl HttpReader {
Expand Down
2 changes: 1 addition & 1 deletion src/ureq_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub(crate) mod sync {
}
}

/// Sync HTTP client for HTTP Range requests with a buffer optimized for sequential requests.
/// Sync HTTP client for HTTP Range requests with a buffer optimized for sequential reading.
pub type UreqHttpReader = crate::SyncBufferedHttpRangeClient<ureq::Agent>;

impl UreqHttpReader {
Expand Down

0 comments on commit d0b14b3

Please sign in to comment.