pub struct HttpResponse { /* private fields */ }
Expand description
An Http response
Implementations§
Source§impl HttpResponse
impl HttpResponse
pub fn builder() -> HttpResponseBuilder
Source§impl HttpResponse
impl HttpResponse
pub fn parse(stream: impl Into<HttpStream>) -> Result<Self>
pub fn status(&self) -> u16
pub fn content_length(&self) -> usize
Sourcepub fn header(&self, key: &str) -> Option<&str>
pub fn header(&self, key: &str) -> Option<&str>
Get the value of the given header key, if present
pub fn version(&self) -> f32
pub fn headers(&self) -> &HashMap<String, String>
Sourcepub fn body(&mut self) -> Result<Option<&[u8]>>
pub fn body(&mut self) -> Result<Option<&[u8]>>
Reads the body from the stream
into the response’s buffer.
§NOTE
This loads the whole body of the response into memory, and it’ll stick with the response for it’s lifetime. It’s not very efficient memory-wise for responses with big bodies.
For a nicer way to process a response’s body, see the read_body function.
§Errors
If some IO error happens when reading the body from the stream
§Returns
And option of &u8. A None variant means the response doesn’t have a body.
Sourcepub fn has_body(&self) -> Result<bool>
pub fn has_body(&self) -> Result<bool>
Returns true if the stream
has a body,
and false if it’s empty.
This method is preferred to check the presence of a body, over calling body and checking the returned Option, since this function doesn’t allocate memory, nor mutates the response.
§Errors
If some IO error happens in the process of checking the
stream
’s availability