pub struct Response { /* private fields */ }Expand description
HTTP response wrapper providing convenience methods for body consumption.
Implementations§
Source§impl Response
impl Response
Sourcepub fn status(&self) -> StatusCode
pub fn status(&self) -> StatusCode
HTTP status code.
Sourcepub fn header(&self, name: &str) -> Option<&str>
pub fn header(&self, name: &str) -> Option<&str>
Return the first value of the named response header as a UTF-8 string,
or None if the header is absent or its value is not valid UTF-8.
§Example
use oxihttp_client::Client;
let client = Client::builder().build()?;
let resp = client.get("http://example.com/new-resource")?.send().await?;
if let Some(location) = resp.header("location") {
println!("redirected to: {location}");
}
if let Some(nonce) = resp.header("replay-nonce") {
println!("ACME nonce: {nonce}");
}Sourcepub fn content_length(&self) -> Option<u64>
pub fn content_length(&self) -> Option<u64>
Content-Length header as u64 if present and valid.
Sourcepub async fn body_bytes(self) -> Result<Bytes, OxiHttpError>
pub async fn body_bytes(self) -> Result<Bytes, OxiHttpError>
Consume the body and return raw bytes, auto-decompressing if enabled.
Sourcepub async fn body_text(self) -> Result<String, OxiHttpError>
pub async fn body_text(self) -> Result<String, OxiHttpError>
Consume the body and return it as a UTF-8 string.
Sourcepub async fn body_json<T: DeserializeOwned>(self) -> Result<T, OxiHttpError>
pub async fn body_json<T: DeserializeOwned>(self) -> Result<T, OxiHttpError>
Consume the body and deserialize it as JSON.
Sourcepub fn error_for_status(self) -> Result<Self, OxiHttpError>
pub fn error_for_status(self) -> Result<Self, OxiHttpError>
Return an error if the response status is a client (4xx) or server (5xx) error.
Returns Ok(self) for success and redirect status codes.
Sourcepub fn content_type(&self) -> Option<&str>
pub fn content_type(&self) -> Option<&str>
Returns the Content-Type header value as a string, if present.
Parse all Set-Cookie response headers using oxihttp_core::Cookie::parse_set_cookie.
Returns an empty Vec when there are no Set-Cookie headers or none parse
successfully.
Sourcepub fn body_stream(self) -> BodyStream
pub fn body_stream(self) -> BodyStream
Consume the response and return the body as an async stream of chunks.