#[non_exhaustive]pub struct HttpResponse {
pub status: u16,
pub headers: Vec<(String, String)>,
pub body: Vec<u8>,
}Expand description
A response returned by a HttpClient, with the whole body read.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.status: u16§headers: Vec<(String, String)>§body: Vec<u8>Implementations§
Source§impl HttpResponse
impl HttpResponse
Sourcepub fn new(status: u16, body: impl Into<Vec<u8>>) -> HttpResponse
pub fn new(status: u16, body: impl Into<Vec<u8>>) -> HttpResponse
Creates a response without headers.
Sourcepub fn with_header(
self,
name: impl Into<String>,
value: impl Into<String>,
) -> HttpResponse
pub fn with_header( self, name: impl Into<String>, value: impl Into<String>, ) -> HttpResponse
Adds a header.
Sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
Returns true for a 2xx status.
Sourcepub fn error_for_status(self) -> Result<HttpResponse, HttpError>
pub fn error_for_status(self) -> Result<HttpResponse, HttpError>
Returns the response for a 2xx status, otherwise HttpError::Status with the API’s
error message.
Sourcepub fn header(&self, name: &str) -> Option<&str>
pub fn header(&self, name: &str) -> Option<&str>
Returns the value of the first header with this name, ignoring case.
Sourcepub fn content_type(&self) -> Option<&str>
pub fn content_type(&self) -> Option<&str>
The Content-Type header without its parameters, None when it is missing or empty.
Sourcepub fn json<T>(&self) -> Result<T, HttpError>where
T: DeserializeOwned,
pub fn json<T>(&self) -> Result<T, HttpError>where
T: DeserializeOwned,
Parses the body as JSON.
Trait Implementations§
Source§impl Clone for HttpResponse
impl Clone for HttpResponse
Source§fn clone(&self) -> HttpResponse
fn clone(&self) -> HttpResponse
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for HttpResponse
impl Debug for HttpResponse
Source§impl PartialEq for HttpResponse
impl PartialEq for HttpResponse
impl StructuralPartialEq for HttpResponse
Auto Trait Implementations§
impl Forget for HttpResponse
impl Freeze for HttpResponse
impl Move for HttpResponse
impl RefUnwindSafe for HttpResponse
impl Send for HttpResponse
impl Sync for HttpResponse
impl Unpin for HttpResponse
impl UnsafeUnpin for HttpResponse
impl UnwindSafe for HttpResponse
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