pub struct Downloader { /* private fields */ }Expand description
A reusable HTTP downloader.
Implementations§
Source§impl Downloader
impl Downloader
Sourcepub fn new() -> VtaResult<Downloader>
pub fn new() -> VtaResult<Downloader>
Build a secure downloader (TLS via rustls, connect timeout). Plaintext
http:// to non-loopback hosts is rejected and https→http downgrade
redirects are refused.
Sourcepub fn insecure() -> VtaResult<Downloader>
pub fn insecure() -> VtaResult<Downloader>
Build a downloader that additionally permits plaintext http:// to any
host. This is the dangerous insecure opt-in (audit M6/C1): callers
must surface it to the operator. https→http downgrade redirects are
still refused.
Sourcepub fn with_retries(self, retries: u32) -> Self
pub fn with_retries(self, retries: u32) -> Self
Override the per-URL retry count (default 3).
Sourcepub fn download(&self, url: &str, dest: &Path) -> VtaResult<()>
pub fn download(&self, url: &str, dest: &Path) -> VtaResult<()>
Download url into dest, resuming a partial <dest>.part if present and
retrying transient failures with backoff. No size ceiling.
Sourcepub fn download_capped(
&self,
url: &str,
dest: &Path,
max: Option<u64>,
) -> VtaResult<()>
pub fn download_capped( &self, url: &str, dest: &Path, max: Option<u64>, ) -> VtaResult<()>
Like Downloader::download but aborts with an error if more than
max bytes would be written (audit M8). None means no ceiling.
Sourcepub fn download_capped_with_progress(
&self,
url: &str,
dest: &Path,
max: Option<u64>,
progress: Option<&ProgressFn<'_>>,
) -> VtaResult<()>
pub fn download_capped_with_progress( &self, url: &str, dest: &Path, max: Option<u64>, progress: Option<&ProgressFn<'_>>, ) -> VtaResult<()>
Like Downloader::download_capped, but reports streamed bytes through
progress (e.g. to advance a progress bar). Used for the registry index
download where the total length is not known in advance.
Sourcepub fn download_any(
&self,
urls: &[String],
dest: &Path,
max: Option<u64>,
) -> VtaResult<()>
pub fn download_any( &self, urls: &[String], dest: &Path, max: Option<u64>, ) -> VtaResult<()>
Try a primary URL then mirrors/alternates in order, returning on the first
success. A mirror that serves wrong bytes is caught by the caller’s hash
verification, so falling through mirrors is safe (docs/13-offline.md).
max, when set, caps the bytes accepted from any single URL (M8).
Sourcepub fn download_any_with_progress(
&self,
urls: &[String],
dest: &Path,
max: Option<u64>,
progress: Option<&ProgressFn<'_>>,
) -> VtaResult<()>
pub fn download_any_with_progress( &self, urls: &[String], dest: &Path, max: Option<u64>, progress: Option<&ProgressFn<'_>>, ) -> VtaResult<()>
Like Downloader::download_any, but reports streamed bytes through
progress so the caller can render a download bar (bytes/total/ETA).