-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split sync and async body into distinct types (#262)
Make the big split between synchronous responses and asynchronous responses, which offers ergonomic improvements and encourages users towards using the right methods by default as discussed in #202. This required the following changes: - Split `Body` into two distinct types: `AsyncBody` and `Body`, which are asynchronous only and synchronous only, respectively. - Split `ResponseExt` into three traits: `ResponseExt` for methods that don't use the body, `ReadResponseExt` for synchronous methods that read from the body, and `AsyncReadResponseExt` for async methods that read from the body. This offers some ergonomic improvements as well, as the async response methods can drop the `_async` suffix, and Rust will automatically resolve to the correct method depending on whether the response is async or not. This split also enables a new capability that I did not think of before, which is that you can now use anything implementing `Read` as a request body such as `File` when using the synchronous API. For those not using async at all, this is a significant improvement! Fixes #202.
- Loading branch information
Showing
24 changed files
with
1,447 additions
and
701 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
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
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,26 @@ | ||
//! Sample program that demonstrates how to upload a file using a `PUT` request. | ||
//! Since 1.0, you can use a `File` as the request body directly, or anything | ||
//! implementing `Read`, when using the synchronous APIs. | ||
//! | ||
//! If using the asynchronous APIs, you will need an asynchronous version of | ||
//! `File` such as the one provided by [`async-fs`](https://docs.rs/async-fs). | ||
//! Isahc does not provide an implementation for you. | ||
use isahc::prelude::*; | ||
use std::fs::File; | ||
|
||
fn main() -> Result<(), isahc::Error> { | ||
// We're opening the source code file you are looking at right now for | ||
// reading. | ||
let file = File::open(file!())?; | ||
|
||
// Perform the upload. | ||
let mut response = isahc::put("https://httpbin.org/put", file)?; | ||
|
||
// Print interesting info from the response. | ||
println!("Status: {}", response.status()); | ||
println!("Headers: {:#?}", response.headers()); | ||
print!("{}", response.text()?); | ||
|
||
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.