Struct reqwest::Body
[−]
[src]
pub struct Body { /* fields omitted */ }
Body type for a request.
Methods
impl Body
[src]
fn new<R: Read + Send + '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.
let file = File::open("national_secrets.txt")?; let body = Body::new(file);
If you have a set of bytes, like String
or Vec<u8>
, using the
From
implementations for Body
will store the data in a manner
it can be reused.
let s = "A stringy body"; let body = Body::from(s);
fn sized<R: Read + Send + 'static>(reader: R, len: u64) -> Body
Create a Body
from a Reader
where we can predict the size in
advance, but where we don't want to load the data in memory. This
is useful if we need to ensure Content-Length
is passed with the
request.
let file = File::open("a_large_file.txt")?; let file_size = file.metadata()?.len(); let body = Body::sized(file, file_size);
Trait Implementations
impl Debug for Body
[src]
impl From<Vec<u8>> for Body
[src]
impl From<String> for Body
[src]
impl From<&'static [u8]> for Body
[src]
fn from(s: &'static [u8]) -> Body
Performs the conversion.