pub struct Response { /* private fields */ }
Expand description
Represents the result of an HTTP request
This object implements Read
, which means
you can read it in a streaming fashion or
use the accessors to read it into memory.
Implementations
sourceimpl Response
impl Response
sourcepub fn status(&self) -> StatusCode
pub fn status(&self) -> StatusCode
Returns the HTTP status code.
is_success()
is the most convenient way to
make sure the message was received.
sourcepub fn content_length(&self) -> Option<u64>
pub fn content_length(&self) -> Option<u64>
Gets the Content-Length of the returned body.
If the server reported the length of the returned body,
then this returns it, and None if the server didn’t
specify. This value is available before the body
is read with data()
or text_as_utf8()
It may also be a lie.
sourcepub fn text_as_utf8(&mut self) -> Result<String>
pub fn text_as_utf8(&mut self) -> Result<String>
Read the entire document and interpret it as UTF-8.
Read the entire message body into memory.
sourcepub fn copy_to<W: Write + ?Sized>(&mut self, w: &mut W) -> Result<u64>
pub fn copy_to<W: Write + ?Sized>(&mut self, w: &mut W) -> Result<u64>
Copies this Read object into another Write object
Returns the number of bytes read or an Error if the request failed at some point.
sourcepub fn header<K: AsHeaderName>(&self, k: K) -> Option<&HeaderValue>
pub fn header<K: AsHeaderName>(&self, k: K) -> Option<&HeaderValue>
Gets a specific HTTP header by name
sourcepub fn remote_address(&self) -> Result<&str>
pub fn remote_address(&self) -> Result<&str>
The remote ip address for this connection
Trait Implementations
sourceimpl Read for Response
impl Read for Response
sourcefn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
1.36.0 · sourcefn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
Like read
, except that it reads into a slice of buffers. Read more
sourcefn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)Determines if this Read
er has an efficient read_vectored
implementation. Read more
1.0.0 · sourcefn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>
Read all bytes until EOF in this source, placing them into buf
. Read more
1.0.0 · sourcefn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
Read all bytes until EOF in this source, appending them to buf
. Read more
1.6.0 · sourcefn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
Read the exact number of bytes required to fill buf
. Read more
sourcefn read_buf(&mut self, buf: &mut ReadBuf<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: &mut ReadBuf<'_>) -> Result<(), Error>
read_buf
)Pull some bytes from this source into the specified buffer. Read more
sourcefn read_buf_exact(&mut self, buf: &mut ReadBuf<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, buf: &mut ReadBuf<'_>) -> Result<(), Error>
read_buf
)Read the exact number of bytes required to fill buf
. Read more
1.0.0 · sourcefn by_ref(&mut self) -> &mut Self
fn by_ref(&mut self) -> &mut Self
Creates a “by reference” adaptor for this instance of Read
. Read more
Auto Trait Implementations
impl RefUnwindSafe for Response
impl !Send for Response
impl !Sync for Response
impl Unpin for Response
impl UnwindSafe for Response
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more