pub struct AsyncHttpRangeReader { /* private fields */ }
Expand description
An AsyncRangeReader
enables reading from a file over HTTP using range requests.
See the crate
level documentation for more information.
The general entrypoint is AsyncHttpRangeReader::new
. Depending on the
CheckSupportMethod
, this will either call AsyncHttpRangeReader::initial_tail_request
or
AsyncHttpRangeReader::initial_head_request
to send the initial request and then
AsyncHttpRangeReader::from_tail_response
or AsyncHttpRangeReader::from_head_response
to
initialize the async reader. If you want to apply a caching layer, you can send the initial head
(or tail) request yourself with your cache headers (e.g. through the
http-cache-semantics crate):
async fn get_reader_cached(
url: Url,
) -> Result<Option<AsyncHttpRangeReader>, AsyncHttpRangeReaderError> {
let etag = "63c550e8-5ae";
let client = reqwest::Client::new();
let response = client
.head(url.clone())
.header(reqwest::header::IF_NONE_MATCH, etag)
.send()
.await?;
if response.status() == reqwest::StatusCode::NOT_MODIFIED {
Ok(None)
} else {
let reader = AsyncHttpRangeReader::from_head_response(client, response, url, HeaderMap::default()).await?;
Ok(Some(reader))
}
}
Implementations§
source§impl AsyncHttpRangeReader
impl AsyncHttpRangeReader
sourcepub async fn new(
client: impl Into<ClientWithMiddleware>,
url: Url,
check_method: CheckSupportMethod,
extra_headers: HeaderMap
) -> Result<(Self, HeaderMap), AsyncHttpRangeReaderError>
pub async fn new( client: impl Into<ClientWithMiddleware>, url: Url, check_method: CheckSupportMethod, extra_headers: HeaderMap ) -> Result<(Self, HeaderMap), AsyncHttpRangeReaderError>
Construct a new AsyncHttpRangeReader
.
sourcepub async fn initial_tail_request(
client: impl Into<ClientWithMiddleware>,
url: Url,
initial_chunk_size: u64,
extra_headers: HeaderMap
) -> Result<Response, AsyncHttpRangeReaderError>
pub async fn initial_tail_request( client: impl Into<ClientWithMiddleware>, url: Url, initial_chunk_size: u64, extra_headers: HeaderMap ) -> Result<Response, AsyncHttpRangeReaderError>
Send an initial range request to determine if the remote accepts range
requests. This will return a number of bytes from the end of the stream. Use the
initial_chunk_size
parameter to define how many bytes should be requested from the end.
sourcepub async fn from_tail_response(
client: impl Into<ClientWithMiddleware>,
tail_request_response: Response,
url: Url,
extra_headers: HeaderMap
) -> Result<Self, AsyncHttpRangeReaderError>
pub async fn from_tail_response( client: impl Into<ClientWithMiddleware>, tail_request_response: Response, url: Url, extra_headers: HeaderMap ) -> Result<Self, AsyncHttpRangeReaderError>
Initialize the reader from AsyncHttpRangeReader::initial_tail_request
(or a user
provided response that also has a range of bytes from the end as body)
sourcepub async fn initial_head_request(
client: impl Into<ClientWithMiddleware>,
url: Url,
extra_headers: HeaderMap
) -> Result<Response, AsyncHttpRangeReaderError>
pub async fn initial_head_request( client: impl Into<ClientWithMiddleware>, url: Url, extra_headers: HeaderMap ) -> Result<Response, AsyncHttpRangeReaderError>
Send an initial range request to determine if the remote accepts range requests and get the content length
sourcepub async fn from_head_response(
client: impl Into<ClientWithMiddleware>,
head_response: Response,
url: Url,
extra_headers: HeaderMap
) -> Result<Self, AsyncHttpRangeReaderError>
pub async fn from_head_response( client: impl Into<ClientWithMiddleware>, head_response: Response, url: Url, extra_headers: HeaderMap ) -> Result<Self, AsyncHttpRangeReaderError>
Initialize the reader from AsyncHttpRangeReader::initial_head_request
(or a user
provided response the)
sourcepub async fn requested_ranges(&self) -> Vec<Range<u64>>
pub async fn requested_ranges(&self) -> Vec<Range<u64>>
Returns the ranges that this instance actually performed HTTP requests for.
Trait Implementations§
source§impl AsyncRead for AsyncHttpRangeReader
impl AsyncRead for AsyncHttpRangeReader
source§impl AsyncSeek for AsyncHttpRangeReader
impl AsyncSeek for AsyncHttpRangeReader
Auto Trait Implementations§
impl !Freeze for AsyncHttpRangeReader
impl !RefUnwindSafe for AsyncHttpRangeReader
impl Send for AsyncHttpRangeReader
impl Sync for AsyncHttpRangeReader
impl Unpin for AsyncHttpRangeReader
impl !UnwindSafe for AsyncHttpRangeReader
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