pub struct HttpResponse {
pub status: StatusCode,
pub headers: HeaderMap,
pub body: Bytes,
pub url: Url,
}Expand description
Complete HTTP response after the body has been read into memory.
Fields§
§status: StatusCodeResponse status code.
headers: HeaderMapResponse headers.
body: BytesResponse body bytes.
url: UrlFinal resolved URL.
Implementations§
Source§impl HttpResponse
impl HttpResponse
Sourcepub fn new(
status: StatusCode,
headers: HeaderMap,
body: Bytes,
url: Url,
) -> Self
pub fn new( status: StatusCode, headers: HeaderMap, body: Bytes, url: Url, ) -> Self
Assembles a response from its parts (as produced by crate::HttpClient::execute).
§Parameters
status: HTTP status line code.headers: Response headers.body: Full body bytes.url: Final URL after redirects.
§Returns
New HttpResponse.
Sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
Returns whether HttpResponse::status is a success code (StatusCode::is_success).
§Returns
true for 2xx responses.
Sourcepub fn text(&self) -> HttpResult<String>
pub fn text(&self) -> HttpResult<String>
Interprets HttpResponse::body as UTF-8 text.
§Returns
Ok(String) or HttpError::decode with status/URL context on invalid UTF-8.
Sourcepub fn json<T>(&self) -> HttpResult<T>where
T: DeserializeOwned,
pub fn json<T>(&self) -> HttpResult<T>where
T: DeserializeOwned,
Deserializes HttpResponse::body as JSON into T.
§Type parameters
T: Type implementingserde::de::DeserializeOwned.
§Returns
Ok(T) or HttpError::decode with status/URL context.
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 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl !Freeze 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