pub struct RawResponse { /* private fields */ }Expand description
An in-memory HTTP response as returned by the shell, used in the middleware chain.
Implementations§
Source§impl RawResponse
impl RawResponse
Sourcepub fn status(&self) -> StatusCode
pub fn status(&self) -> StatusCode
Get the HTTP status code.
§Examples
let res = client.get("https://httpbin.org/get").await?;
assert_eq!(res.status(), 200);Sourcepub fn version(&self) -> Option<Version>
pub fn version(&self) -> Option<Version>
Get the HTTP protocol version.
§Examples
use crux_http::http::Version;
let res = client.get("https://httpbin.org/get").await?;
assert_eq!(res.version(), Some(Version::HTTP_11));Sourcepub fn header_all(&self, name: impl AsHeaderName) -> GetAll<'_, HeaderValue>
pub fn header_all(&self, name: impl AsHeaderName) -> GetAll<'_, HeaderValue>
Get all values for a header name.
Sourcepub fn header(&self, name: impl AsHeaderName) -> Option<&HeaderValue>
pub fn header(&self, name: impl AsHeaderName) -> Option<&HeaderValue>
Get a header value by name (returns the first value for that name).
§Examples
let res = client.get("https://httpbin.org/get").await?;
assert!(res.header("Content-Length").is_some());Sourcepub fn header_mut(
&mut self,
name: impl AsHeaderName,
) -> Option<&mut HeaderValue>
pub fn header_mut( &mut self, name: impl AsHeaderName, ) -> Option<&mut HeaderValue>
Get a header value mutably.
Sourcepub fn remove_header(&mut self, name: impl AsHeaderName) -> Option<HeaderValue>
pub fn remove_header(&mut self, name: impl AsHeaderName) -> Option<HeaderValue>
Remove a header.
Sourcepub fn insert_header(
&mut self,
name: impl IntoHeaderName,
value: HeaderValue,
) -> Option<HeaderValue>
pub fn insert_header( &mut self, name: impl IntoHeaderName, value: HeaderValue, ) -> Option<HeaderValue>
Insert an HTTP header, replacing any existing value.
Returns the previous value for that header name, if any.
Sourcepub fn append_header(
&mut self,
name: impl IntoHeaderName,
value: HeaderValue,
) -> bool
pub fn append_header( &mut self, name: impl IntoHeaderName, value: HeaderValue, ) -> bool
Append an HTTP header, keeping any existing values.
Returns true if the value was appended to an existing entry, false if it was the first
value for that name.
Sourcepub fn iter(&self) -> Iter<'_, HeaderValue>
pub fn iter(&self) -> Iter<'_, HeaderValue>
An iterator visiting all header (name, value) pairs in arbitrary order.
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, HeaderValue>
pub fn iter_mut(&mut self) -> IterMut<'_, HeaderValue>
An iterator visiting all header (name, value) pairs with mutable values.
Sourcepub fn header_names(&self) -> Keys<'_, HeaderValue>
pub fn header_names(&self) -> Keys<'_, HeaderValue>
An iterator visiting all header names in arbitrary order.
Sourcepub fn header_values(&self) -> Values<'_, HeaderValue>
pub fn header_values(&self) -> Values<'_, HeaderValue>
An iterator visiting all header values in arbitrary order.
Sourcepub fn content_type(&self) -> Option<Mime>
pub fn content_type(&self) -> Option<Mime>
Get the response content type as a Mime.
§Examples
let res = client.get("https://httpbin.org/json").await?;
assert_eq!(res.content_type(), Some(mime::APPLICATION_JSON));Sourcepub fn body_bytes(&mut self) -> Result<Vec<u8>>
pub fn body_bytes(&mut self) -> Result<Vec<u8>>
Sourcepub fn body_string(&mut self) -> Result<String>
pub fn body_string(&mut self) -> Result<String>
Sourcepub fn body_json<T: DeserializeOwned>(&mut self) -> Result<T>
pub fn body_json<T: DeserializeOwned>(&mut self) -> Result<T>
Sourcepub fn body_form<T: DeserializeOwned>(&mut self) -> Result<T>
pub fn body_form<T: DeserializeOwned>(&mut self) -> Result<T>
Reads and deserializes the entire response body from form encoding.
§Errors
Returns an error if deserialisation fails.
§Examples
#[derive(Deserialize, Serialize)]
struct Body { apples: u32 }
let mut res = client.get("https://api.example.com/v1/response").await?;
let Body { apples } = res.body_form()?;