pub struct Response { /* private fields */ }
Expand description
A Response to a submitted Request
.
Implementations
sourceimpl Response
impl Response
sourcepub fn status(&self) -> StatusCode
pub fn status(&self) -> StatusCode
Get the StatusCode
of this Response
.
sourcepub fn headers_mut(&mut self) -> &mut HeaderMap
pub fn headers_mut(&mut self) -> &mut HeaderMap
Get a mutable reference to the Headers
of this Response
.
Retrieve the cookies contained in the response.
Note that invalid ‘Set-Cookie’ headers will be ignored.
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 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-length
header. - The response is gzipped and automatically decoded (thus changing the actual decoded length).
sourcepub fn body_mut(&mut self) -> &mut Decoder
pub fn body_mut(&mut self) -> &mut Decoder
Get a mutable reference to the response body.
The chunks from the body may be decoded, depending on the gzip
option on the ClientBuilder
.
sourcepub fn text_with_charset(
&mut self,
default_encoding: &str
) -> impl Future<Item = String, Error = Error>
pub fn text_with_charset(
&mut self,
default_encoding: &str
) -> impl Future<Item = String, Error = Error>
Get the response text given a specific encoding
sourcepub fn json<T: DeserializeOwned>(
&mut self
) -> impl Future<Item = T, Error = Error>
pub fn json<T: DeserializeOwned>(
&mut self
) -> impl Future<Item = T, Error = Error>
Try to deserialize the response body as JSON using serde
.
sourcepub fn error_for_status(self) -> Result<Self>
pub fn error_for_status(self) -> Result<Self>
Turn a response into an error if the server returned an error.
Example
fn on_response(res: Response) {
match res.error_for_status() {
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)
);
}
}
}
sourcepub fn error_for_status_ref(&self) -> Result<&Self>
pub fn error_for_status_ref(&self) -> Result<&Self>
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 !RefUnwindSafe for Response
impl Send for Response
impl !Sync for Response
impl Unpin for Response
impl !UnwindSafe for Response
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more