#[non_exhaustive]pub struct HttpResponse {
pub url: Url,
pub status: StatusCode,
pub headers: HeaderMap,
pub body: Bytes,
pub redirect_chain: Vec<Url>,
}Expand description
A fully buffered HTTP response.
§Examples
use bytes::Bytes;
use http::{HeaderMap, StatusCode};
use millipede_core::http_client::HttpResponse;
use url::Url;
let response = HttpResponse::new(
Url::parse("https://example.com/")?,
StatusCode::OK,
HeaderMap::new(),
Bytes::from_static(b"hello"),
);
assert_eq!(response.text(), "hello");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.url: UrlFinal URL after redirects.
status: StatusCodeHTTP response status.
headers: HeaderMapHTTP response headers.
body: BytesFully buffered response body.
redirect_chain: Vec<Url>Intermediate redirect URLs in order, excluding the final URL.
Implementations§
Source§impl HttpResponse
impl HttpResponse
Sourcepub fn new(
url: Url,
status: StatusCode,
headers: HeaderMap,
body: Bytes,
) -> Self
pub fn new( url: Url, status: StatusCode, headers: HeaderMap, body: Bytes, ) -> Self
Creates a response with an empty redirect chain.
Sourcepub fn with_redirect_chain(self, chain: Vec<Url>) -> Self
pub fn with_redirect_chain(self, chain: Vec<Url>) -> Self
Sets the intermediate redirect URLs.
Sourcepub fn text(&self) -> Cow<'_, str>
pub fn text(&self) -> Cow<'_, str>
Returns the body decoded as UTF-8, replacing invalid sequences lossily.
Sourcepub fn json<T: DeserializeOwned>(&self) -> Result<T, Error>
pub fn json<T: DeserializeOwned>(&self) -> Result<T, Error>
Deserializes the response 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 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