pub struct FetchSession { /* private fields */ }Expand description
Drives the fetchurl client protocol as a state machine.
Determines which URLs to try and in what order: servers first
(with source URLs forwarded as X-Source-Urls), then direct
source URLs in random order.
The caller iterates through attempts, makes HTTP requests with their preferred library, and reports results back to the session.
Implementations§
Source§impl FetchSession
impl FetchSession
Sourcepub fn new(
algo: &str,
hash: &str,
source_urls: &[impl AsRef<str>],
) -> Result<Self, Error>
pub fn new( algo: &str, hash: &str, source_urls: &[impl AsRef<str>], ) -> Result<Self, Error>
Create a new fetch session.
algo: hash algorithm name (e.g."sha256")hash: expected hash in hexsource_urls: direct source URLs (tried after servers, in random order)
Sourcepub fn next_attempt(&mut self) -> Option<FetchAttempt>
pub fn next_attempt(&mut self) -> Option<FetchAttempt>
Get the next attempt to try.
Returns None when all attempts are exhausted or the session is
finished (after report_success or
report_partial).
If the HTTP request fails without writing any bytes, just call
next_attempt() again to try the next source.
Sourcepub fn report_success(&mut self)
pub fn report_success(&mut self)
Report that the current attempt succeeded. Stops the session.
Sourcepub fn report_partial(&mut self)
pub fn report_partial(&mut self)
Report that bytes were already written to the output before a failure. Stops the session — no further attempts since the output is tainted.
Sourcepub fn verifier<W: Write>(&self, writer: W) -> HashVerifier<W> ⓘ
pub fn verifier<W: Write>(&self, writer: W) -> HashVerifier<W> ⓘ
Create a HashVerifier wrapping the given writer.
Pipe the HTTP response body through the verifier, then call
HashVerifier::finish to check the hash.