pub struct Body { /* private fields */ }Expand description
An asynchronous request body.
Implementations§
Source§impl Body
impl Body
Sourcepub fn new<R: Read + 'static>(reader: R) -> Body
pub fn new<R: Read + 'static>(reader: R) -> Body
Instantiate a Body from a reader.
§Note
While allowing for many types to be used, these bodies do not have
a way to reset to the beginning and be reused. This means that when
encountering a 307 or 308 status code, instead of repeating the
request at the new location, the Response will be returned with
the redirect status code set.
Sourcepub fn sized<R: Read + 'static>(reader: R, len: u64) -> Body
pub fn sized<R: Read + 'static>(reader: R, len: u64) -> Body
Create a Body from a Read where the size is known in advance
but the data should not be fully loaded into memory. This will
set the Content-Length header and stream from the Read.
Sourcepub fn as_bytes(&self) -> Option<&[u8]>
pub fn as_bytes(&self) -> Option<&[u8]>
Returns the body as a byte slice if the body is already buffered in
memory. For streamed requests this method returns None.
Sourcepub fn buffer(&mut self) -> Result<&[u8], Error>
Available on non-crate feature async only.
pub fn buffer(&mut self) -> Result<&[u8], Error>
async only.Converts streamed requests to their buffered equivalent and returns a reference to the buffer. If the request is already buffered, this has no effect.
Be aware that for large requests this method is expensive and may cause your program to run out of memory.