pub struct Response<Body> { /* private fields */ }
Expand description
An HTTP Response that will be passed to in a message to an apps update function
Implementations§
source§impl<Body> Response<Body>
impl<Body> Response<Body>
sourcepub fn version(&self) -> Option<Version>
pub fn version(&self) -> Option<Version>
Get the HTTP protocol version.
§Examples
use crux_http::http::Version;
assert_eq!(res.version(), Some(Version::Http1_1));
sourcepub fn header_mut(
&mut self,
name: impl Into<HeaderName>,
) -> Option<&mut HeaderValues>
pub fn header_mut( &mut self, name: impl Into<HeaderName>, ) -> Option<&mut HeaderValues>
Get an HTTP header mutably.
sourcepub fn remove_header(
&mut self,
name: impl Into<HeaderName>,
) -> Option<HeaderValues>
pub fn remove_header( &mut self, name: impl Into<HeaderName>, ) -> Option<HeaderValues>
Remove a header.
sourcepub fn insert_header(
&mut self,
key: impl Into<HeaderName>,
value: impl ToHeaderValues,
)
pub fn insert_header( &mut self, key: impl Into<HeaderName>, value: impl ToHeaderValues, )
Insert an HTTP header.
sourcepub fn append_header(
&mut self,
key: impl Into<HeaderName>,
value: impl ToHeaderValues,
)
pub fn append_header( &mut self, key: impl Into<HeaderName>, value: impl ToHeaderValues, )
Append an HTTP header.
sourcepub fn iter_mut(&mut self) -> IterMut<'_>
pub fn iter_mut(&mut self) -> IterMut<'_>
An iterator visiting all header pairs in arbitrary order, with mutable references to the values.
sourcepub fn header_names(&self) -> Names<'_>
pub fn header_names(&self) -> Names<'_>
An iterator visiting all header names in arbitrary order.
sourcepub fn header_values(&self) -> Values<'_>
pub fn header_values(&self) -> Values<'_>
An iterator visiting all header values in arbitrary order.
sourcepub fn content_type(&self) -> Option<Mime>
pub fn content_type(&self) -> Option<Mime>
pub fn body(&self) -> Option<&Body>
pub fn take_body(&mut self) -> Option<Body>
pub fn with_body<NewBody>(self, body: NewBody) -> Response<NewBody>
source§impl Response<Vec<u8>>
impl Response<Vec<u8>>
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>
Reads the entire response body into a string.
This method can be called after the body has already been read, but will produce an empty buffer.
§Encodings
If the “encoding” feature is enabled, this method tries to decode the body with the encoding that is specified in the Content-Type header. If the header does not specify an encoding, UTF-8 is assumed. If the “encoding” feature is disabled, Surf only supports reading UTF-8 response bodies. The “encoding” feature is enabled by default.
§Errors
Any I/O error encountered while reading the body is immediately returned
as an Err
.
If the body cannot be interpreted because the encoding is unsupported or
incorrect, an Err
is returned.
§Examples
let string: String = res.body_string()?;
assert_eq!(string, "hello");
sourcepub fn body_json<T: DeserializeOwned>(&mut self) -> Result<T>
pub fn body_json<T: DeserializeOwned>(&mut self) -> Result<T>
Reads and deserialized the entire request body from json.
§Errors
Any I/O error encountered while reading the body is immediately returned
as an Err
.
If the body cannot be interpreted as valid json for the target type T
,
an Err
is returned.
§Examples
#[derive(Deserialize, Serialize)]
struct Ip {
ip: String
}
let Ip { ip } = res.body_json()?;
assert_eq!(ip, "127.0.0.1");
Trait Implementations§
source§impl<'de, Body> Deserialize<'de> for Response<Body>where
Body: Deserialize<'de>,
impl<'de, Body> Deserialize<'de> for Response<Body>where
Body: Deserialize<'de>,
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl<Body> Eq for Response<Body>where
Body: Eq,
Auto Trait Implementations§
impl<Body> Freeze for Response<Body>where
Body: Freeze,
impl<Body> RefUnwindSafe for Response<Body>where
Body: RefUnwindSafe,
impl<Body> Send for Response<Body>where
Body: Send,
impl<Body> Sync for Response<Body>where
Body: Sync,
impl<Body> Unpin for Response<Body>where
Body: Unpin,
impl<Body> UnwindSafe for Response<Body>where
Body: UnwindSafe,
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)