Struct BodyWithConfig
pub struct BodyWithConfig<'a> { /* private fields */ }
dep_ureq
only.Expand description
Configuration of how to read the body.
Obtained via one of:
Implementations§
§impl<'a> BodyWithConfig<'a>
impl<'a> BodyWithConfig<'a>
pub fn limit(self, value: u64) -> BodyWithConfig<'a>
pub fn limit(self, value: u64) -> BodyWithConfig<'a>
Limit the response body.
Controls how many bytes we should read before throwing an error. This is used to ensure RAM isn’t exhausted by a server sending a very large response body.
The default limit is u64::MAX
(unlimited).
pub fn lossy_utf8(self, value: bool) -> BodyWithConfig<'a>
pub fn lossy_utf8(self, value: bool) -> BodyWithConfig<'a>
Replace invalid utf-8 chars.
true
means that broken utf-8 characters are replaced by a question mark ?
(not utf-8 replacement char). This happens after charset conversion regardless of
whether the charset feature is enabled or not.
The default is false
.
pub fn reader(self) -> BodyReader<'a> ⓘ
pub fn reader(self) -> BodyReader<'a> ⓘ
Creates a reader.
The reader is either shared or owned, depending on with_config
or into_with_config
.
§Example of owned vs shared
// Creates an owned reader.
let reader = ureq::get("https://httpbin.org/get")
.call()?
.into_body()
// takes ownership of Body
.into_with_config()
.limit(10)
.reader();
// Creates a shared reader.
let reader = ureq::get("https://httpbin.org/get")
.call()?
.body_mut()
// borrows Body
.with_config()
.limit(10)
.reader();
pub fn read_to_string(self) -> Result<String, Error> ⓘ
pub fn read_to_string(self) -> Result<String, Error> ⓘ
Read into string.
Caution: without a preceeding limit()
, this
becomes an unbounded sized String
. A bad server could exhaust your memory.
§Example
// Reads max 10k to a String.
let string = ureq::get("https://httpbin.org/get")
.call()?
.body_mut()
.with_config()
// Important. Limits body to 10k
.limit(10_000)
.read_to_string()?;
pub fn read_to_vec(self) -> Result<Vec<u8>, Error> ⓘ
pub fn read_to_vec(self) -> Result<Vec<u8>, Error> ⓘ
Read into vector.
Caution: without a preceeding limit()
, this
becomes an unbounded sized Vec
. A bad server could exhaust your memory.
§Example
// Reads max 10k to a Vec.
let myvec = ureq::get("https://httpbin.org/get")
.call()?
.body_mut()
.with_config()
// Important. Limits body to 10k
.limit(10_000)
.read_to_vec()?;
Auto Trait Implementations§
impl<'a> !Freeze for BodyWithConfig<'a>
impl<'a> !RefUnwindSafe for BodyWithConfig<'a>
impl<'a> Send for BodyWithConfig<'a>
impl<'a> Sync for BodyWithConfig<'a>
impl<'a> Unpin for BodyWithConfig<'a>
impl<'a> !UnwindSafe for BodyWithConfig<'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
Source§impl<T> ByteSized for T
impl<T> ByteSized for T
Source§const BYTE_ALIGN: usize = _
const BYTE_ALIGN: usize = _
Source§fn byte_align(&self) -> usize
fn byte_align(&self) -> usize
Source§fn ptr_size_ratio(&self) -> [usize; 2]
fn ptr_size_ratio(&self) -> [usize; 2]
Source§impl<T, R> Chain<R> for Twhere
T: ?Sized,
impl<T, R> Chain<R> for Twhere
T: ?Sized,
Source§impl<T> ExtAny for T
impl<T> ExtAny for T
Source§fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
TypeId
of Self
using a custom hasher.Source§fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
Source§impl<T> ExtMem for Twhere
T: ?Sized,
impl<T> ExtMem for Twhere
T: ?Sized,
Source§const NEEDS_DROP: bool = _
const NEEDS_DROP: bool = _
Source§fn mem_align_of<T>() -> usize
fn mem_align_of<T>() -> usize
Source§fn mem_align_of_val(&self) -> usize
fn mem_align_of_val(&self) -> usize
Source§fn mem_size_of<T>() -> usize
fn mem_size_of<T>() -> usize
Source§fn mem_size_of_val(&self) -> usize
fn mem_size_of_val(&self) -> usize
Source§fn mem_needs_drop(&self) -> bool
fn mem_needs_drop(&self) -> bool
true
if dropping values of this type matters. Read moreSource§fn mem_forget(self)where
Self: Sized,
fn mem_forget(self)where
Self: Sized,
self
without running its destructor. Read moreSource§fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
Source§unsafe fn mem_zeroed<T>() -> T
unsafe fn mem_zeroed<T>() -> T
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§fn mem_as_bytes(&self) -> &[u8] ⓘ
fn mem_as_bytes(&self) -> &[u8] ⓘ
unsafe_slice
only.§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Hook for T
impl<T> Hook for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more