Struct reqwest::blocking::Body[][src]

pub struct Body { /* fields omitted */ }
Expand description

The body of a Request.

In most cases, this is not needed directly, as the RequestBuilder.body method uses Into<Body>, which allows passing many things (like a string or vector of bytes).

Implementations

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);

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.

let file = File::open("a_large_file.txt")?;
let file_size = file.metadata()?.len();
let body = Body::sized(file, file_size);

Returns the body as a byte slice if the body is already buffered in memory. For streamed requests this method returns None.

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.

Trait Implementations

Formats the value using the given formatter. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more