Expand description
HTTP storage backend using async reqwest + Tokio. HTTP storage backend with embedded Tokio runtime.
This module provides an HTTP storage backend that wraps the reqwest async
client in an embedded Tokio runtime. This allows the backend to present a
synchronous StorageBackend interface while leveraging async I/O internally
for efficient concurrent operations.
§Architecture
The HttpBackend embeds a Tokio runtime (Arc<Runtime>) and uses
runtime.block_on() to execute async operations synchronously. This design:
- Maintains compatibility with the synchronous
StorageBackendtrait - Enables efficient connection pooling and concurrent requests via
reqwest - Provides async benefits (low memory overhead per connection) without requiring callers to use async/await
§Redirect Handling
reqwest’s built-in redirect policy drops certain headers (including Range)
on cross-origin redirects. Since CDNs like GitHub Releases → Azure Blob
require cross-origin redirects with range headers, this backend disables
auto-redirects and follows them manually, re-sending all headers on each hop.
§Thread Safety
The backend is fully thread-safe (Send + Sync):
- The
reqwest::Clientis designed for concurrent use - The
Arc<Runtime>is shared safely across threads - Multiple threads can call
read_exact()concurrently without coordination
§Security
This backend validates URLs to prevent SSRF attacks:
- Blocks access to localhost and private networks by default
- Set
allow_restricted: trueonly in trusted environments - See
validate_urlfor details
§Examples
use hexz_core::store::http::HttpBackend;
use hexz_core::store::StorageBackend;
let backend = HttpBackend::new(
"https://cdn.example.com/snapshots/data.hxz".to_string(),
false // block restricted IPs
)?;
println!("Snapshot size: {} bytes", backend.len());
let header = backend.read_exact(0, 512)?;
assert_eq!(header.len(), 512);Structs§
- Http
Backend - HTTP storage backend with embedded Tokio runtime.