ResponseLazy

Struct ResponseLazy 

Source
pub struct ResponseLazy {
    pub status_code: i32,
    pub reason_phrase: String,
    pub headers: HashMap<String, String>,
    pub url: String,
    pub stream: HttpStreamBytes,
    /* private fields */
}
Expand description

An HTTP response, which is loaded lazily.

In comparison to Response, this is returned from send_lazy(), where as Response is returned from send().

In practice, “lazy loading” means that the bytes are only loaded as you iterate through them. The bytes are provided in the form of a Result<(u8, usize), minreq::Error>, as the reading operation can fail in various ways. The u8 is the actual byte that was read, and usize is how many bytes we are expecting to read in the future (including this byte). Note, however, that the usize can change, particularly when the Transfer-Encoding is chunked: then it will reflect how many bytes are left of the current chunk. The expected size is capped at 16 KiB to avoid server-side DoS attacks targeted at clients accidentally reserving too much memory.

§Example

// This is how the normal Response works behind the scenes, and
// how you might use ResponseLazy.
let response = minreq::get("http://example.com").send_lazy()?;
let mut vec = Vec::new();
for result in response {
    let (byte, length) = result?;
    vec.reserve(length);
    vec.push(byte);
}

Fields§

§status_code: i32

The status code of the response, eg. 404.

§reason_phrase: String

The reason phrase of the response, eg. “Not Found”.

§headers: HashMap<String, String>

The headers of the response. The header field names (the keys) are all lowercase.

§url: String

The URL of the resource returned in this response. May differ from the request URL if it was redirected or typo corrections were applied (e.g. http://example.com?foo=bar would be corrected to http://example.com/?foo=bar).

§stream: HttpStreamBytes

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.