Skip to main content

FetchSession

Struct FetchSession 

Source
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

Source

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 hex
  • source_urls: direct source URLs (tried after servers, in random order)
Source

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.

Source

pub fn report_success(&mut self)

Report that the current attempt succeeded. Stops the session.

Source

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.

Source

pub fn succeeded(&self) -> bool

Whether the session completed with a successful download.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V