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: i32The status code of the response, eg. 404.
reason_phrase: StringThe 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: StringThe 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