pub struct RestResponse<'a> { /* private fields */ }Expand description
HTTP response. Borrows from the connection’s ResponseReader.
Must be dropped before the next request on the same connection
(same pattern as WebSocket Message<'_>).
Implementations§
Source§impl<'a> RestResponse<'a>
impl<'a> RestResponse<'a>
Sourcepub fn new(
status: u16,
body_len: usize,
resp_reader: &'a ResponseReader,
) -> Self
pub fn new( status: u16, body_len: usize, resp_reader: &'a ResponseReader, ) -> Self
Create a response from parsed data (Content-Length delimited).
Typically called by transport layers after reading and parsing the response.
Sourcepub fn new_chunked(
status: u16,
body: Vec<u8>,
resp_reader: &'a ResponseReader,
) -> Self
pub fn new_chunked( status: u16, body: Vec<u8>, resp_reader: &'a ResponseReader, ) -> Self
Create a response with a decoded chunked body.
Sourcepub fn header(&self, name: &str) -> Option<&str>
pub fn header(&self, name: &str) -> Option<&str>
Look up a response header by name (case-insensitive).
Sourcepub fn body_to_bytes(&self) -> Bytes
pub fn body_to_bytes(&self) -> Bytes
Copy the response body into bytes::Bytes.
Allocates once — copies the body slice into a Bytes handle
that is Send + Clone for cross-thread passing.
ⓘ
let resp = conn.send(req, &mut reader)?;
let body: Bytes = resp.body_to_bytes();
tx.send(body)?;Sourcepub fn header_count(&self) -> usize
pub fn header_count(&self) -> usize
Number of response headers.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for RestResponse<'a>
impl<'a> RefUnwindSafe for RestResponse<'a>
impl<'a> Send for RestResponse<'a>
impl<'a> Sync for RestResponse<'a>
impl<'a> Unpin for RestResponse<'a>
impl<'a> UnsafeUnpin for RestResponse<'a>
impl<'a> UnwindSafe for RestResponse<'a>
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
Mutably borrows from an owned value. Read more