6a41459862fa9db2a903542afcc06460cf39c277
As ENV is process global, modifying it within a thread (as is normal for all test targets in a rust libtest) results in a concurrency data-race. This patch fences the two known cases of needing to modify this by locking all ENV modifications, and collection of data dependent on said modifications, into a narrow path isolated by a Mutex lock, with no test assert!()'s while the Mutex is held ( to avoid a Mutex Posioning ). However, the code doesn't treat lock failure as a special circumstance, and if the lock fails, then the pre-existing risk of conccurent ENV modification returns, and these 2 tests can still randomly fail, but _in that situation_. And as mutexes can _only_ be poisoned by the 2 threads holding this mutex, this regression can now only trip into concurrency issues when either of these 2 tests are already failing from _non test_ assertions, so this patch still improves the status quo substantially. Closes: https://github.com/seanmonstar/reqwest/issues/829
reqwest
An ergonomic, batteries-included HTTP Client for Rust.
- Plain bodies, JSON, urlencoded, multipart
- Customizable redirect policy
- HTTP Proxies
- HTTPS via system-native TLS (or optionally, rustls)
- Cookie Store
- WASM
- Changelog
Example
This asynchronous example uses Tokio and enables some
optional features, so your Cargo.toml could look like this:
[dependencies]
reqwest = { version = "0.10", features = ["json"] }
tokio = { version = "0.2", features = ["full"] }
And then the code:
use std::collections::HashMap;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let resp = reqwest::get("https://httpbin.org/ip")
.await?
.json::<HashMap<String, String>>()
.await?;
println!("{:#?}", resp);
Ok(())
}
Blocking Client
There is an optional "blocking" client API that can be enabled:
[dependencies]
reqwest = { version = "0.10", features = ["blocking", "json"] }
use std::collections::HashMap;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let resp = reqwest::blocking::get("https://httpbin.org/ip")?
.json::<HashMap<String, String>>()?;
println!("{:#?}", resp);
Ok(())
}
Requirements
On Linux:
- OpenSSL 1.0.1, 1.0.2, or 1.1.0 with headers (see https://github.com/sfackler/rust-openssl)
On Windows and macOS:
- Nothing.
Reqwest uses rust-native-tls, which will use the operating system TLS framework if available, meaning Windows and macOS. On Linux, it will use OpenSSL 1.1.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Description
Languages
Rust
99.6%
Nix
0.4%