-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ResponseLazy: Work in buffers, not bytes
When reading a response lazily, we want to work with it efficiently, as buffers of bytes coming out of the OS TCP stack. While we could `Iterator::collect::<Vec<u8>>()` the bytes back together from the current interface, this incurs an extra copy. (And unless optimizations can miraculously burn through all our iteration logic, we'll get an inefficient byte-by-byte copy at that!) Instead, have ResponseLazy just implement Read. Users who want individual bytes can get them with std::io::Bytes; that's what it's for. While we're at it, don't lie about content-length headers that weren't actually there for a chunked transfer.
- Loading branch information
Showing
5 changed files
with
107 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "minreq" | ||
version = "2.11.1-alpha" | ||
version = "3.0.0-alpha" | ||
authors = ["Jens Pitkanen <[email protected]>"] | ||
description = "Simple, minimal-dependency HTTP client" | ||
documentation = "https://docs.rs/minreq" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/// This example shows how a [`Response`] is a [`std::io::Read`], | ||
/// so it can be easily copied to [`std::io::write`], such as stdout | ||
/// or a file. | ||
fn main() -> Result<(), minreq::Error> { | ||
let mut response = minreq::get("http://example.com").send_lazy()?; | ||
std::io::copy(&mut response, &mut std::io::stdout().lock())?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.