pub struct FetchOptions {
pub checksum: Option<[u8; 32]>,
pub retry_policy: RetryPolicy,
pub expected_bytes: Option<u64>,
pub resume_offset: Option<u64>,
pub headers: Arc<[(String, String)]>,
pub on_progress: Option<ProgressCallback>,
pub retry_delay_provider: Option<RetryDelayProvider>,
}Expand description
Configuration for HTTP fetching operations.
§Examples
use pulith_fetch::FetchOptions;
use std::time::Duration;
let options = FetchOptions::default()
.max_retries(5)
.retry_backoff(Duration::from_millis(200))
.header("Authorization", "Bearer token");Fields§
§checksum: Option<[u8; 32]>Expected SHA-256 checksum for verification (optional). If provided, the download will be verified and will fail on mismatch.
retry_policy: RetryPolicyRetry execution policy for transient transfer failures.
expected_bytes: Option<u64>Expected total bytes for this transfer, when known by caller.
resume_offset: Option<u64>Resume offset in bytes. When set, fetcher will request Range: bytes=<offset>-.
headers: Arc<[(String, String)]>Custom HTTP headers to include with requests.
Headers are sent with every request, including retries.
Default: empty
on_progress: Option<ProgressCallback>Progress callback invoked on state transitions and chunk writes.
The callback is invoked:
- On phase transitions (Connecting → Downloading → Verifying → Committing → Completed)
- After each chunk write (during Downloading phase, typically every ~8KB)
- After each retry attempt (back to Connecting phase)
The callback receives a reference to avoid cloning on every invocation.
Default: None
retry_delay_provider: Option<RetryDelayProvider>Optional runtime delay provider for retry backoff sleeping.
When absent, fetcher uses the crate default async sleep mechanism.
Implementations§
Source§impl FetchOptions
impl FetchOptions
Sourcepub fn checksum(self, checksum: Option<[u8; 32]>) -> Self
pub fn checksum(self, checksum: Option<[u8; 32]>) -> Self
Set the expected checksum.
§Examples
use pulith_fetch::FetchOptions;
let hash = [0u8; 32]; // Your expected SHA-256
let options = FetchOptions::default().checksum(Some(hash));Sourcepub fn max_retries(self, max_retries: u32) -> Self
pub fn max_retries(self, max_retries: u32) -> Self
Set the maximum number of retries.
§Examples
use pulith_fetch::FetchOptions;
let options = FetchOptions::default().max_retries(5);Sourcepub fn retry_backoff(self, retry_backoff: Duration) -> Self
pub fn retry_backoff(self, retry_backoff: Duration) -> Self
Set the base retry backoff duration.
§Examples
use pulith_fetch::FetchOptions;
use std::time::Duration;
let options = FetchOptions::default()
.retry_backoff(Duration::from_millis(200));Sourcepub fn retry_policy(self, retry_policy: RetryPolicy) -> Self
pub fn retry_policy(self, retry_policy: RetryPolicy) -> Self
Set the full retry policy object directly.
Sourcepub fn expected_bytes(self, expected_bytes: Option<u64>) -> Self
pub fn expected_bytes(self, expected_bytes: Option<u64>) -> Self
Set expected transfer size for progress/reporting without HEAD lookup.
Sourcepub fn resume_offset(self, resume_offset: Option<u64>) -> Self
pub fn resume_offset(self, resume_offset: Option<u64>) -> Self
Set resume offset in bytes for ranged fetch.
Sourcepub fn header(self, key: impl Into<String>, value: impl Into<String>) -> Self
pub fn header(self, key: impl Into<String>, value: impl Into<String>) -> Self
Add a single custom HTTP header.
§Examples
use pulith_fetch::FetchOptions;
let options = FetchOptions::default()
.header("Authorization", "Bearer token")
.header("User-Agent", "MyApp/1.0");Sourcepub fn headers(self, headers: Vec<(String, String)>) -> Self
pub fn headers(self, headers: Vec<(String, String)>) -> Self
Set multiple custom HTTP headers at once.
This replaces any existing headers.
§Examples
use pulith_fetch::FetchOptions;
let headers = vec![
("Authorization".to_string(), "Bearer token".to_string()),
("User-Agent".to_string(), "MyApp/1.0".to_string()),
];
let options = FetchOptions::default().headers(headers);Sourcepub fn on_progress(
self,
on_progress: Arc<dyn Fn(&Progress) + Send + Sync>,
) -> Self
pub fn on_progress( self, on_progress: Arc<dyn Fn(&Progress) + Send + Sync>, ) -> Self
Set the progress callback.
§Examples
use pulith_fetch::{FetchOptions, FetchPhase};
use std::sync::Arc;
let options = FetchOptions::default()
.on_progress(Arc::new(|progress| {
match progress.phase {
FetchPhase::Downloading => {
if let Some(pct) = progress.percentage() {
println!("Progress: {:.1}%", pct);
}
}
FetchPhase::Completed => println!("Done!"),
_ => {}
}
}));Sourcepub fn retry_delay_provider(self, provider: RetryDelayProvider) -> Self
pub fn retry_delay_provider(self, provider: RetryDelayProvider) -> Self
Set an async retry-delay provider for runtime-agnostic backoff handling.
Trait Implementations§
Source§impl Clone for FetchOptions
impl Clone for FetchOptions
Source§fn clone(&self) -> FetchOptions
fn clone(&self) -> FetchOptions
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more