Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: seanmonstar/reqwest
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.11.26
Choose a base ref
...
head repository: seanmonstar/reqwest
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.11.27
Choose a head ref
  • 4 commits
  • 12 files changed
  • 3 contributors

Commits on Mar 14, 2024

  1. (wasm) fix: Form::text on wasm setting octet-stream mime type and fil…

    …e name. (#2174)
    
    Unfortunately JS's fetch API is somewhat limited and only supports two
    options for multipart form data parts:
    1) String with no file name and no mime type (which should be
    interpreted as text/plain).
    2) Blob with a file name ("blob" if not provided by the user) and a
    mime type if provided by the user.
    
    Until this commit, reqwest always used the latter option, so when a user
    tried to add a text part with no file name, it would be sent with a mime
    type of `application/octet-stream` and the filename "blob".
    
    While we can't make the behaviour identical to the native
    implementation, we can do a best-effort approach, using option (1) as
    long as the user hasn't set a file name or a non plain text mime type.
    ashdnazg authored Mar 14, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    6904889 View commit details

Commits on Mar 18, 2024

  1. refactor: Migrate trust-dns to hickory-dns

    Signed-off-by: Xuanwo <github@xuanwo.io>
    Xuanwo authored and seanmonstar committed Mar 18, 2024

    Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    2fe53c5 View commit details

Commits on Mar 19, 2024

  1. docs: add note about sponsors/support

    seanmonstar committed Mar 19, 2024
    Copy the full SHA
    d0d2b47 View commit details
  2. v0.11.27

    seanmonstar committed Mar 19, 2024
    Copy the full SHA
    cf69fd4 View commit details
Showing with 260 additions and 131 deletions.
  1. +3 −3 .github/workflows/ci.yml
  2. +5 −0 CHANGELOG.md
  3. +6 −4 Cargo.toml
  4. +9 −19 README.md
  5. +57 −22 src/async_impl/client.rs
  6. +35 −11 src/blocking/client.rs
  7. +4 −4 src/dns/{trust_dns.rs → hickory.rs}
  8. +2 −2 src/dns/mod.rs
  9. +12 −2 src/lib.rs
  10. +59 −42 src/wasm/body.rs
  11. +62 −16 src/wasm/multipart.rs
  12. +6 −6 tests/client.rs
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -83,7 +83,7 @@ jobs:
- "feat.: stream"
- "feat.: socks/default-tls"
- "feat.: socks/rustls-tls"
- "feat.: trust-dns"
- "feat.: hickory-dns"

include:
- name: linux / stable
@@ -151,8 +151,8 @@ jobs:
features: "--features socks"
- name: "feat.: socks/rustls-tls"
features: "--features socks,rustls-tls"
- name: "feat.: trust-dns"
features: "--features trust-dns"
- name: "feat.: hickory-dns"
features: "--features hickory-dns"

steps:
- name: Checkout
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## v0.11.27

- Add `hickory-dns` feature, deprecating `trust-dns`.
- (wasm) Fix `Form::text()` to not set octet-stream for plain text fields.

## v0.11.26

- Revert `system-configuration` upgrade, which broke MSRV on macOS.
10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "reqwest"
version = "0.11.26" # remember to update html_root_url
version = "0.11.27" # remember to update html_root_url
description = "higher level HTTP client library"
keywords = ["http", "request", "client"]
categories = ["web-programming::http-client", "wasm"]
@@ -57,7 +57,9 @@ json = ["serde_json"]

multipart = ["mime_guess"]

trust-dns = ["trust-dns-resolver"]
# Deprecated, remove this feature while bumping minor versions.
trust-dns = ["hickory-dns"]
hickory-dns = ["hickory-resolver"]

stream = ["tokio/fs", "tokio-util", "wasm-streams"]

@@ -137,8 +139,8 @@ tokio-util = { version = "0.7.1", default-features = false, features = ["codec",
## socks
tokio-socks = { version = "0.5.1", optional = true }

## trust-dns
trust-dns-resolver = { version = "0.23", optional = true, features = ["tokio-runtime"] }
## hickory-dns
hickory-resolver = { version = "0.24", optional = true, features = ["tokio-runtime"] }

# HTTP/3 experimental support
h3 = { version = "0.0.3", optional = true }
28 changes: 9 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -7,13 +7,13 @@

An ergonomic, batteries-included HTTP Client for Rust.

- Async and blocking `Client`s
- Plain bodies, JSON, urlencoded, multipart
- Customizable redirect policy
- HTTP Proxies
- HTTPS via system-native TLS (or optionally, rustls)
- Cookie Store
- WASM
- [Changelog](CHANGELOG.md)


## Example
@@ -43,25 +43,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
}
```

## Blocking Client
## Commercial Support

There is an optional "blocking" client API that can be enabled:

```toml
[dependencies]
reqwest = { version = "0.11", features = ["blocking", "json"] }
```

```rust,no_run
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(())
}
```
For private advice, support, reviews, access to the maintainer, and the like, reach out for [commercial support][sponsor].

## Requirements

@@ -93,3 +77,9 @@ Licensed under either of
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.

## Sponsors

Support this project by becoming a [sponsor][].

[sponsor]: https://seanmonstar.com/sponsor
79 changes: 57 additions & 22 deletions src/async_impl/client.rs
Original file line number Diff line number Diff line change
@@ -33,8 +33,8 @@ use crate::async_impl::h3_client::{H3Client, H3ResponseFuture};
use crate::connect::Connector;
#[cfg(feature = "cookies")]
use crate::cookie;
#[cfg(feature = "trust-dns")]
use crate::dns::trust_dns::TrustDnsResolver;
#[cfg(feature = "hickory-dns")]
use crate::dns::hickory::HickoryDnsResolver;
use crate::dns::{gai::GaiResolver, DnsResolverWithOverrides, DynResolver, Resolve};
use crate::error;
use crate::into_url::try_uri;
@@ -135,7 +135,7 @@ struct Config {
nodelay: bool,
#[cfg(feature = "cookies")]
cookie_store: Option<Arc<dyn cookie::CookieStore>>,
trust_dns: bool,
hickory_dns: bool,
error: Option<crate::Error>,
https_only: bool,
#[cfg(feature = "http3")]
@@ -218,7 +218,7 @@ impl ClientBuilder {
http2_keep_alive_while_idle: false,
local_address: None,
nodelay: true,
trust_dns: cfg!(feature = "trust-dns"),
hickory_dns: cfg!(feature = "hickory-dns"),
#[cfg(feature = "cookies")]
cookie_store: None,
https_only: false,
@@ -267,12 +267,12 @@ impl ClientBuilder {
headers.get(USER_AGENT).cloned()
}

let mut resolver: Arc<dyn Resolve> = match config.trust_dns {
let mut resolver: Arc<dyn Resolve> = match config.hickory_dns {
false => Arc::new(GaiResolver::new()),
#[cfg(feature = "trust-dns")]
true => Arc::new(TrustDnsResolver::default()),
#[cfg(not(feature = "trust-dns"))]
true => unreachable!("trust-dns shouldn't be enabled unless the feature is"),
#[cfg(feature = "hickory-dns")]
true => Arc::new(HickoryDnsResolver::default()),
#[cfg(not(feature = "hickory-dns"))]
true => unreachable!("hickory-dns shouldn't be enabled unless the feature is"),
};
if let Some(dns_resolver) = config.dns_resolver {
resolver = dns_resolver;
@@ -1526,32 +1526,67 @@ impl ClientBuilder {
self
}

/// Enables the [trust-dns](trust_dns_resolver) async resolver instead of a default threadpool using `getaddrinfo`.
/// Enables the [hickory-dns](hickory_resolver) async resolver instead of a default threadpool
/// using `getaddrinfo`.
///
/// If the `trust-dns` feature is turned on, the default option is enabled.
/// If the `hickory-dns` feature is turned on, the default option is enabled.
///
/// # Optional
///
/// This requires the optional `trust-dns` feature to be enabled
#[cfg(feature = "trust-dns")]
#[cfg_attr(docsrs, doc(cfg(feature = "trust-dns")))]
/// This requires the optional `hickory-dns` feature to be enabled
#[cfg(feature = "hickory-dns")]
#[cfg_attr(docsrs, doc(cfg(feature = "hickory-dns")))]
#[deprecated(note = "use `hickory_dns` instead")]
pub fn trust_dns(mut self, enable: bool) -> ClientBuilder {
self.config.trust_dns = enable;
self.config.hickory_dns = enable;
self
}

/// Disables the trust-dns async resolver.
/// Enables the [hickory-dns](hickory_resolver) async resolver instead of a default threadpool
/// using `getaddrinfo`.
///
/// This method exists even if the optional `trust-dns` feature is not enabled.
/// This can be used to ensure a `Client` doesn't use the trust-dns async resolver
/// even if another dependency were to enable the optional `trust-dns` feature.
/// If the `hickory-dns` feature is turned on, the default option is enabled.
///
/// # Optional
///
/// This requires the optional `hickory-dns` feature to be enabled
#[cfg(feature = "hickory-dns")]
#[cfg_attr(docsrs, doc(cfg(feature = "hickory-dns")))]
pub fn hickory_dns(mut self, enable: bool) -> ClientBuilder {
self.config.hickory_dns = enable;
self
}

/// Disables the hickory-dns async resolver.
///
/// This method exists even if the optional `hickory-dns` feature is not enabled.
/// This can be used to ensure a `Client` doesn't use the hickory-dns async resolver
/// even if another dependency were to enable the optional `hickory-dns` feature.
#[deprecated(note = "use `no_hickory_dns` instead")]
pub fn no_trust_dns(self) -> ClientBuilder {
#[cfg(feature = "trust-dns")]
#[cfg(feature = "hickory-dns")]
{
self.hickory_dns(false)
}

#[cfg(not(feature = "hickory-dns"))]
{
self
}
}

/// Disables the hickory-dns async resolver.
///
/// This method exists even if the optional `hickory-dns` feature is not enabled.
/// This can be used to ensure a `Client` doesn't use the hickory-dns async resolver
/// even if another dependency were to enable the optional `hickory-dns` feature.
pub fn no_hickory_dns(self) -> ClientBuilder {
#[cfg(feature = "hickory-dns")]
{
self.trust_dns(false)
self.hickory_dns(false)
}

#[cfg(not(feature = "trust-dns"))]
#[cfg(not(feature = "hickory-dns"))]
{
self
}
46 changes: 35 additions & 11 deletions src/blocking/client.rs
Original file line number Diff line number Diff line change
@@ -789,26 +789,50 @@ impl ClientBuilder {
self.with_inner(move |inner| inner.use_preconfigured_tls(tls))
}

/// Enables the [trust-dns](trust_dns_resolver) async resolver instead of a default threadpool using `getaddrinfo`.
/// Enables the [hickory-dns](hickory_resolver) async resolver instead of a default threadpool using `getaddrinfo`.
///
/// If the `trust-dns` feature is turned on, the default option is enabled.
/// If the `hickory-dns` feature is turned on, the default option is enabled.
///
/// # Optional
///
/// This requires the optional `trust-dns` feature to be enabled
#[cfg(feature = "trust-dns")]
#[cfg_attr(docsrs, doc(cfg(feature = "trust-dns")))]
/// This requires the optional `hickory-dns` feature to be enabled
#[cfg(feature = "hickory-dns")]
#[cfg_attr(docsrs, doc(cfg(feature = "hickory-dns")))]
#[deprecated(note = "use `hickory_dns` instead", since = "0.12.0")]
pub fn trust_dns(self, enable: bool) -> ClientBuilder {
self.with_inner(|inner| inner.trust_dns(enable))
self.with_inner(|inner| inner.hickory_dns(enable))
}

/// Disables the trust-dns async resolver.
/// Enables the [hickory-dns](hickory_resolver) async resolver instead of a default threadpool using `getaddrinfo`.
///
/// This method exists even if the optional `trust-dns` feature is not enabled.
/// This can be used to ensure a `Client` doesn't use the trust-dns async resolver
/// even if another dependency were to enable the optional `trust-dns` feature.
/// If the `hickory-dns` feature is turned on, the default option is enabled.
///
/// # Optional
///
/// This requires the optional `hickory-dns` feature to be enabled
#[cfg(feature = "hickory-dns")]
#[cfg_attr(docsrs, doc(cfg(feature = "hickory-dns")))]
pub fn hickory_dns(self, enable: bool) -> ClientBuilder {
self.with_inner(|inner| inner.hickory_dns(enable))
}

/// Disables the hickory-dns async resolver.
///
/// This method exists even if the optional `hickory-dns` feature is not enabled.
/// This can be used to ensure a `Client` doesn't use the hickory-dns async resolver
/// even if another dependency were to enable the optional `hickory-dns` feature.
#[deprecated(note = "use `no_hickory_dns` instead", since = "0.12.0")]
pub fn no_trust_dns(self) -> ClientBuilder {
self.with_inner(|inner| inner.no_trust_dns())
self.with_inner(|inner| inner.no_hickory_dns())
}

/// Disables the hickory-dns async resolver.
///
/// This method exists even if the optional `hickory-dns` feature is not enabled.
/// This can be used to ensure a `Client` doesn't use the hickory-dns async resolver
/// even if another dependency were to enable the optional `hickory-dns` feature.
pub fn no_hickory_dns(self) -> ClientBuilder {
self.with_inner(|inner| inner.no_hickory_dns())
}

/// Restrict the Client to be used with HTTPS only requests.
8 changes: 4 additions & 4 deletions src/dns/trust_dns.rs → src/dns/hickory.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! DNS resolution via the [trust_dns_resolver](https://github.com/bluejekyll/trust-dns) crate
//! DNS resolution via the [hickory-resolver](https://github.com/hickory-dns/hickory-dns) crate
use hickory_resolver::{lookup_ip::LookupIpIntoIter, system_conf, TokioAsyncResolver};
use hyper::client::connect::dns::Name;
use once_cell::sync::OnceCell;
use trust_dns_resolver::{lookup_ip::LookupIpIntoIter, system_conf, TokioAsyncResolver};

use std::io;
use std::net::SocketAddr;
@@ -12,7 +12,7 @@ use super::{Addrs, Resolve, Resolving};

/// Wrapper around an `AsyncResolver`, which implements the `Resolve` trait.
#[derive(Debug, Default, Clone)]
pub(crate) struct TrustDnsResolver {
pub(crate) struct HickoryDnsResolver {
/// Since we might not have been called in the context of a
/// Tokio Runtime in initialization, so we must delay the actual
/// construction of the resolver.
@@ -23,7 +23,7 @@ struct SocketAddrs {
iter: LookupIpIntoIter,
}

impl Resolve for TrustDnsResolver {
impl Resolve for HickoryDnsResolver {
fn resolve(&self, name: Name) -> Resolving {
let resolver = self.clone();
Box::pin(async move {
4 changes: 2 additions & 2 deletions src/dns/mod.rs
Original file line number Diff line number Diff line change
@@ -4,6 +4,6 @@ pub use resolve::{Addrs, Resolve, Resolving};
pub(crate) use resolve::{DnsResolverWithOverrides, DynResolver};

pub(crate) mod gai;
#[cfg(feature = "hickory-dns")]
pub(crate) mod hickory;
pub(crate) mod resolve;
#[cfg(feature = "trust-dns")]
pub(crate) mod trust_dns;
14 changes: 12 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -27,6 +27,11 @@
//! - [The Rust Cookbook](https://rust-lang-nursery.github.io/rust-cookbook/web/clients.html)
//! - [Reqwest Repository Examples](https://github.com/seanmonstar/reqwest/tree/master/examples)
//!
//! ## Commercial Support
//!
//! For private advice, support, reviews, access to the maintainer, and the
//! like, reach out for [commercial support][sponsor].
//!
//! ## Making a GET request
//!
//! For a single request, you can use the [`get`][get] shortcut method.
@@ -195,7 +200,7 @@
//! - **multipart**: Provides functionality for multipart forms.
//! - **stream**: Adds support for `futures::Stream`.
//! - **socks**: Provides SOCKS5 proxy support.
//! - **trust-dns**: Enables a trust-dns async resolver instead of default
//! - **hickory-dns**: Enables a hickory-dns async resolver instead of default
//! threadpool using `getaddrinfo`.
//!
//! ## Unstable Features
@@ -215,7 +220,11 @@
//! RUSTFLAGS="--cfg reqwest_unstable" cargo build
//! ```
//!
//! [hyper]: http://hyper.rs
//! ## Sponsors
//!
//! Support this project by becoming a [sponsor][].
//!
//! [hyper]: https://hyper.rs
//! [blocking]: ./blocking/index.html
//! [client]: ./struct.Client.html
//! [response]: ./struct.Response.html
@@ -225,6 +234,7 @@
//! [redirect]: crate::redirect
//! [Proxy]: ./struct.Proxy.html
//! [cargo-features]: https://doc.rust-lang.org/stable/cargo/reference/manifest.html#the-features-section
//! [sponsor]: https://seanmonstar.com/sponsor
#[cfg(all(feature = "http3", not(reqwest_unstable)))]
compile_error!(
Loading