pub struct BodyBuilder { /* private fields */ }Expand description
Builder for creating a response body.
This is useful for testing, or for Middleware that
returns another body than the requested one.
§Example
use ureq::Body;
use http::Response;
let body = Body::builder()
.mime_type("text/plain")
.charset("utf-8")
.data("Hello world!");
let mut response = Response::builder()
.status(200)
.header("content-type", "text/plain; charset=utf-8")
.body(body)?;
let text = response
.body_mut()
.read_to_string()?;
assert_eq!(text, "Hello world!");Implementations§
source§impl BodyBuilder
impl BodyBuilder
sourcepub fn mime_type(self, mime_type: impl Into<String>) -> Self
pub fn mime_type(self, mime_type: impl Into<String>) -> Self
Set the mime type of the body.
This does not set any HTTP headers. Affects Body decoding.
use ureq::Body;
let body = Body::builder()
.mime_type("text/plain")
.data("Hello world!");sourcepub fn charset(self, charset: impl Into<String>) -> Self
pub fn charset(self, charset: impl Into<String>) -> Self
Set the mime type of the body
This does not set any HTTP headers. Affects Body decoding.
use ureq::Body;
let body = Body::builder()
.mime_type("text/plain")
.charset("utf-8")
.data("Hello world!");sourcepub fn limit(self, l: u64) -> Self
pub fn limit(self, l: u64) -> Self
Limit how much data is to be released from the body.
This does not set any HTTP headers. Affects Body decoding.
use ureq::Body;
let body = Body::builder()
.mime_type("text/plain")
.charset("utf-8")
.limit(5)
// This will be limited to "Hello"
.data("Hello world!");Auto Trait Implementations§
impl Freeze for BodyBuilder
impl RefUnwindSafe for BodyBuilder
impl Send for BodyBuilder
impl Sync for BodyBuilder
impl Unpin for BodyBuilder
impl UnwindSafe for BodyBuilder
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