pub struct HttpClient { /* private fields */ }Expand description
HTTP transport for fetching control files and byte ranges.
Implementations§
Source§impl HttpClient
impl HttpClient
Sourcepub fn new() -> Self
pub fn new() -> Self
A client permitting plain HTTP, with a bound on reaching a host.
zsync is routinely served over HTTP and across mirror redirects, so
the scheme policy is permissive on purpose. An embedder with a
stricter one, 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.
CONNECT_TIMEOUT and RESOLVE_TIMEOUT apply. Neither bounds the
transfer itself, so a mirror that trickles bytes for an hour is left
alone; they only cap how long a host that never answers can cost.
Sourcepub fn with_agent(agent: Agent) -> Self
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.
pub fn fetch_control_file(&self, url: &str) -> Result<ControlFile, HttpError>
Sourcepub fn fetch_range_reader(
&self,
url: &str,
start: u64,
end: u64,
) -> Result<HttpRangeReader, HttpError>
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.