pub struct ResumableResponse { /* private fields */ }Expand description
A wrapper for reqwest::Response to allow for resumable byte streams
Implementations§
Source§impl ResumableResponse
impl ResumableResponse
Sourcepub fn response(self) -> Response
pub fn response(self) -> Response
Get the underlying reqwest::Response
Sourcepub fn bytes_stream_resumable(
self,
) -> impl Stream<Item = Result<Bytes, Error>> + Send + Unpin
pub fn bytes_stream_resumable( self, ) -> impl Stream<Item = Result<Bytes, Error>> + Send + Unpin
Convert the response into a Stream of Bytes from the body.
§Example
use futures_util::StreamExt;
use reqwest_partial_retry::ClientExt;
let client = reqwest::Client::new().resumable();
let request = client.get("http://httpbin.org/ip").build().unwrap();
let mut stream = client
.execute_resumable(request)
.await?
.bytes_stream_resumable();
while let Some(item) = stream.next().await {
println!("Bytes: {:?}", item?);
}Methods from Deref<Target = Response>§
Sourcepub fn status(&self) -> StatusCode
pub fn status(&self) -> StatusCode
Get the StatusCode of this Response.
Sourcepub fn content_length(&self) -> Option<u64>
pub fn content_length(&self) -> Option<u64>
Get the content-length of this response, if known.
Reasons it may not be known:
- The server didn’t send a
content-lengthheader. - The response is compressed and automatically decoded (thus changing the actual decoded length).
Sourcepub fn remote_addr(&self) -> Option<SocketAddr>
pub fn remote_addr(&self) -> Option<SocketAddr>
Get the remote address used to get this Response.
Sourcepub fn extensions(&self) -> &Extensions
pub fn extensions(&self) -> &Extensions
Returns a reference to the associated extensions.
Sourcepub fn error_for_status_ref(&self) -> Result<&Response, Error>
pub fn error_for_status_ref(&self) -> Result<&Response, Error>
Turn a reference to a response into an error if the server returned an error.
§Example
fn on_response(res: &Response) {
match res.error_for_status_ref() {
Ok(_res) => (),
Err(err) => {
// asserting a 400 as an example
// it could be any status between 400...599
assert_eq!(
err.status(),
Some(reqwest::StatusCode::BAD_REQUEST)
);
}
}
}Trait Implementations§
Auto Trait Implementations§
impl !Freeze for ResumableResponse
impl !RefUnwindSafe for ResumableResponse
impl !UnwindSafe for ResumableResponse
impl Send for ResumableResponse
impl Sync for ResumableResponse
impl Unpin for ResumableResponse
impl UnsafeUnpin for ResumableResponse
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
Mutably borrows from an owned value. Read more