pub struct HyperDirectClient { /* private fields */ }Expand description
A lightweight HTTP client using hyper directly.
Intended for the hot download path: simple HTTP range GETs with no proxy and no complex auth. It avoids reqwest’s abstraction overhead (middleware, redirect-policy objects, default headers plumbing) while keeping a connection pool for reuse across segments.
HTTPS is supported via hyper’s connector only when a TLS backend is wired in; for the plain-HTTP hot path this client is sufficient. HTTPS fallback to reqwest remains available.
Implementations§
Source§impl HyperDirectClient
impl HyperDirectClient
Sourcepub async fn download_range(
&self,
url: &str,
offset: u64,
length: Option<u64>,
) -> Result<Bytes>
pub async fn download_range( &self, url: &str, offset: u64, length: Option<u64>, ) -> Result<Bytes>
Download a byte range from url and collect it into Bytes.
length = Some(n)requestsbytes={offset}-{offset+n-1}.length = Nonerequestsbytes={offset}-(read to end of body).
Status handling mirrors HttpSegmentDownloader::download_range:
206 Partial Content: OK.200 OK: warn (server ignored Range) and proceed.416 Range Not Satisfiable: recoverable error.- other
4xx: fatal error. 5xx: recoverable server error.
The body is accumulated into a BytesMut (sized by the smaller of
length and MAX_INITIAL_CAPACITY) and frozen into a zero-copy
Bytes.
Sourcepub async fn download_range_stream(
&self,
url: &str,
offset: u64,
length: Option<u64>,
) -> Result<impl Stream<Item = Result<Bytes, Error>>>
pub async fn download_range_stream( &self, url: &str, offset: u64, length: Option<u64>, ) -> Result<impl Stream<Item = Result<Bytes, Error>>>
Download a byte range and return the body as a stream of Bytes chunks.
The caller is responsible for consuming the stream (e.g. writing chunks
to disk). Each item is Result<Bytes, std::io::Error>; hyper errors are
mapped to std::io::Error.
Status handling here is stricter than download_range: only 2xx and
206 are accepted; any other status is an error before streaming begins.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for HyperDirectClient
impl !UnwindSafe for HyperDirectClient
impl Freeze for HyperDirectClient
impl Send for HyperDirectClient
impl Sync for HyperDirectClient
impl Unpin for HyperDirectClient
impl UnsafeUnpin for HyperDirectClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more