Skip to main content

HttpClient

Struct HttpClient 

Source
pub struct HttpClient { /* private fields */ }
Expand description

HTTP transport for fetching control files and byte ranges.

Implementations§

Source§

impl HttpClient

Source

pub fn new() -> Self

A client with ureq’s default policy, permitting plain HTTP.

zsync is routinely served over HTTP and across mirror redirects, so the defaults are permissive on purpose. An embedder with a stricter policy, such as one that must refuse a downgrade to HTTP or pin its own trust roots, should build an agent and pass it to HttpClient::with_agent rather than relying on these.

Source

pub fn with_agent(agent: Agent) -> Self

A client using a caller-supplied agent.

The agent carries the whole transport policy: TLS roots, whether a redirect may downgrade to HTTP, timeouts and proxies. Supplying one keeps that decision with the embedder, which is the only place that knows what the transferred bytes are trusted for.

Source

pub fn fetch_control_file(&self, url: &str) -> Result<ControlFile, HttpError>

Source

pub fn fetch_range_reader( &self, url: &str, start: u64, end: u64, ) -> Result<HttpRangeReader, HttpError>

A reader over start..=end of url.

The reader is capped at the requested length. Without that cap the origin decides how much the client reads: a response longer than the range is consumed in full, and callers that accumulate it, such as block assembly, grow a buffer to match. Bytes past the range were never asked for and are of no use, so they are not read.

Source

pub fn fetch_range( &self, url: &str, start: u64, end: u64, ) -> Result<Vec<u8>, HttpError>

Source

pub fn fetch_ranges( &self, url: &str, ranges: &[(u64, u64)], blocksize: usize, ) -> Result<Vec<(u64, Vec<u8>)>, HttpError>

Trait Implementations§

Source§

impl Default for HttpClient

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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.