Skip to content

Commit

Permalink
Merge branch 'master' into expose-streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
Xuanwo authored Sep 4, 2024
2 parents afb613c + cc3dd51 commit 9452f57
Show file tree
Hide file tree
Showing 34 changed files with 797 additions and 164 deletions.
16 changes: 13 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ jobs:
- "feat.: rustls-tls"
- "feat.: rustls-tls-manual-roots"
- "feat.: rustls-tls-native-roots"
- "feat.: rustls-tls-no-provider"
- "feat.: native-tls"
- "feat.: default-tls and rustls-tls"
- "feat.: rustls-tls and rustls-tls-no-provider"
- "feat.: cookies"
- "feat.: blocking"
- "feat.: blocking only"
Expand Down Expand Up @@ -131,8 +133,12 @@ jobs:
features: "--no-default-features --features rustls-tls-manual-roots"
- name: "feat.: rustls-tls-native-roots"
features: "--no-default-features --features rustls-tls-native-roots"
- name: "feat.: rustls-tls-no-provider"
features: "--no-default-features --features rustls-tls-no-provider"
- name: "feat.: native-tls"
features: "--features native-tls"
- name: "feat.: rustls-tls and rustls-tls-no-provider"
features: "--features rustls-tls,rustls-tls-no-provider"
- name: "feat.: default-tls and rustls-tls"
features: "--features rustls-tls"
- name: "feat.: cookies"
Expand Down Expand Up @@ -212,8 +218,11 @@ jobs:
with:
toolchain: 'stable'

#- name: Check
# run: RUSTFLAGS="--cfg reqwest_unstable" cargo check --features http3
- name: Check
run: cargo test --features http3
env:
RUSTFLAGS: --cfg reqwest_unstable
RUSTDOCFLAGS: --cfg reqwest_unstable

docs:
name: Docs
Expand Down Expand Up @@ -263,7 +272,7 @@ jobs:
run: |
cargo clean
cargo update -Z minimal-versions
cargo update -p proc-macro2 --precise 1.0.60
cargo update -p proc-macro2 --precise 1.0.62
cargo check
cargo check --all-features
Expand Down Expand Up @@ -291,6 +300,7 @@ jobs:
cargo update
cargo update -p log --precise 0.4.18
cargo update -p tokio --precise 1.29.1
cargo update -p url --precise 2.5.0
- uses: Swatinem/rust-cache@v2

Expand Down
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
## v0.12.7

- Revert adding `impl Service<http::Request<_>>` for `Client`.

## v0.12.6

- Add support for `danger_accept_invalid_hostnames` for `rustls`.
- Add `impl Service<http::Request<Body>>` for `Client` and `&'_ Client`.
- Add support for `!Sync` bodies in `Body::wrap_stream()`.
- Enable happy eyeballs when `hickory-dns` is used.
- Fix `Proxy` so that `HTTP(S)_PROXY` values take precendence over `ALL_PROXY`.
- Fix `blocking::RequestBuilder::header()` from unsetting `sensitive` on passed header values.

## v0.12.5

- Add `blocking::ClientBuilder::dns_resolver()` method to change DNS resolver in blocking client.
- Add `http3` feature back, still requiring `reqwest_unstable`.
- Add `rustls-tls-no-provider` Cargo feature to use rustls without a crypto provider.
- Fix `Accept-Encoding` header combinations.
- Fix http3 resolving IPv6 addresses.
- Internal: upgrade to rustls 0.23.

## v0.12.4

- Add `zstd` support, enabled with `zstd` Cargo feature.
Expand Down
83 changes: 46 additions & 37 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "reqwest"
version = "0.12.4"
version = "0.12.7"
description = "higher level HTTP client library"
keywords = ["http", "request", "client"]
categories = ["web-programming::http-client", "wasm"]
Expand Down Expand Up @@ -33,19 +33,22 @@ default = ["default-tls", "charset", "http2", "macos-system-configuration"]
# functionality for it.
default-tls = ["dep:hyper-tls", "dep:native-tls-crate", "__tls", "dep:tokio-native-tls"]

http2 = ["h2", "hyper/http2", "hyper-util/http2"]
http2 = ["h2", "hyper/http2", "hyper-util/http2", "hyper-rustls?/http2"]

# Enables native-tls specific functionality not available by default.
native-tls = ["default-tls"]
native-tls-alpn = ["native-tls", "native-tls-crate?/alpn", "hyper-tls?/alpn"]
native-tls-vendored = ["native-tls", "native-tls-crate?/vendored"]

rustls-tls = ["rustls-tls-webpki-roots"]
rustls-tls-manual-roots = ["__rustls"]
rustls-tls-webpki-roots = ["dep:webpki-roots", "__rustls"]
rustls-tls-native-roots = ["dep:rustls-native-certs", "__rustls"]
rustls-tls-no-provider = ["rustls-tls-manual-roots-no-provider"]

blocking = ["futures-channel/sink", "futures-util/io", "futures-util/sink", "tokio/rt-multi-thread", "tokio/sync"]
rustls-tls-manual-roots = ["__rustls", "__rustls-ring"]
rustls-tls-webpki-roots = ["dep:webpki-roots", "hyper-rustls?/webpki-tokio", "__rustls", "__rustls-ring"]
rustls-tls-native-roots = ["dep:rustls-native-certs", "hyper-rustls?/native-tokio", "__rustls", "__rustls-ring"]
rustls-tls-manual-roots-no-provider = ["__rustls"]

blocking = ["dep:futures-channel", "futures-channel?/sink", "futures-util/io", "futures-util/sink", "tokio/sync"]

charset = ["dep:encoding_rs"]

Expand Down Expand Up @@ -75,33 +78,34 @@ socks = ["dep:tokio-socks"]
macos-system-configuration = ["dep:system-configuration"]

# Experimental HTTP/3 client.
# Disabled while waiting for quinn to upgrade.
#http3 = ["rustls-tls-manual-roots", "dep:h3", "dep:h3-quinn", "dep:quinn", "dep:futures-channel"]
http3 = ["rustls-tls-manual-roots", "dep:h3", "dep:h3-quinn", "dep:quinn", "dep:slab", "dep:futures-channel"]


# Internal (PRIVATE!) features used to aid testing.
# Don't rely on these whatsoever. They may disappear at anytime.
# Don't rely on these whatsoever. They may disappear at any time.

# Enables common types used for TLS. Useless on its own.
__tls = ["dep:rustls-pemfile", "tokio/io-util"]

# Enables common rustls code.
# Equivalent to rustls-tls-manual-roots but shorter :)
__rustls = ["dep:hyper-rustls", "dep:tokio-rustls", "dep:rustls", "__tls", "dep:rustls-pemfile", "rustls-pki-types"]
__rustls = ["dep:hyper-rustls", "dep:tokio-rustls", "dep:rustls", "__tls", "dep:rustls-pemfile", "dep:rustls-pki-types"]
__rustls-ring = ["hyper-rustls?/ring", "tokio-rustls?/ring", "rustls?/ring", "quinn?/ring"]

# When enabled, disable using the cached SYS_PROXIES.
__internal_proxy_sys_no_cache = []

[dependencies]
base64 = "0.22"
http = "1"
url = "2.2"
url = "2.4"
bytes = "1.0"
serde = "1.0"
serde_urlencoded = "0.7.1"
tower-service = "0.3"
futures-core = { version = "0.3.0", default-features = false }
futures-util = { version = "0.3.0", default-features = false }
sync_wrapper = "0.1.2"
futures-core = { version = "0.3.28", default-features = false }
futures-util = { version = "0.3.28", default-features = false }
sync_wrapper = { version = "1.0", features = ["futures"] }

# Optional deps...

Expand All @@ -114,15 +118,15 @@ mime_guess = { version = "2.0", default-features = false, optional = true }
encoding_rs = { version = "0.8", optional = true }
http-body = "1"
http-body-util = "0.1"
hyper = { version = "1", features = ["http1", "client"] }
hyper = { version = "1.1", features = ["http1", "client"] }
hyper-util = { version = "0.1.3", features = ["http1", "client", "client-legacy", "tokio"] }
h2 = { version = "0.4", optional = true }
once_cell = "1"
log = "0.4"
once_cell = "1.18"
log = "0.4.17"
mime = "0.3.16"
percent-encoding = "2.1"
percent-encoding = "2.3"
tokio = { version = "1.0", default-features = false, features = ["net", "time"] }
pin-project-lite = "0.2.0"
pin-project-lite = "0.2.11"
ipnet = "2.3"

# Optional deps...
Expand All @@ -134,20 +138,20 @@ native-tls-crate = { version = "0.2.10", optional = true, package = "native-tls"
tokio-native-tls = { version = "0.3.0", optional = true }

# rustls-tls
hyper-rustls = { version = "0.26.0", default-features = false, optional = true }
rustls = { version = "0.22.2", optional = true }
hyper-rustls = { version = "0.27.0", default-features = false, optional = true, features = ["http1", "tls12"] }
rustls = { version = "0.23.4", optional = true, default-features = false, features = ["std", "tls12"] }
rustls-pki-types = { version = "1.1.0", features = ["alloc"] ,optional = true }
tokio-rustls = { version = "0.25", optional = true }
tokio-rustls = { version = "0.26", optional = true, default-features = false, features = ["tls12"] }
webpki-roots = { version = "0.26.0", optional = true }
rustls-native-certs = { version = "0.7", optional = true }

## cookies
cookie_crate = { version = "0.17.0", package = "cookie", optional = true }
cookie_store = { version = "0.20.0", optional = true }
cookie_crate = { version = "0.18.0", package = "cookie", optional = true }
cookie_store = { version = "0.21.0", optional = true }

## compression
async-compression = { version = "0.4.0", default-features = false, features = ["tokio"], optional = true }
tokio-util = { version = "0.7.1", default-features = false, features = ["codec", "io"], optional = true }
tokio-util = { version = "0.7.9", default-features = false, features = ["codec", "io"], optional = true }

## socks
tokio-socks = { version = "0.5.1", optional = true }
Expand All @@ -156,41 +160,43 @@ tokio-socks = { version = "0.5.1", optional = true }
hickory-resolver = { version = "0.24", optional = true, features = ["tokio-runtime"] }

# HTTP/3 experimental support
h3 = { version = "0.0.4", optional = true }
h3-quinn = { version = "0.0.5", optional = true }
quinn = { version = "0.10", default-features = false, features = ["tls-rustls", "ring", "runtime-tokio"], optional = true }
h3 = { version = "0.0.6", optional = true }
h3-quinn = { version = "0.0.7", optional = true }
quinn = { version = "0.11.1", default-features = false, features = ["rustls", "runtime-tokio"], optional = true }
slab = { version = "0.4.9", optional = true } # just to get minimal versions working with quinn
futures-channel = { version = "0.3", optional = true }


[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
env_logger = "0.10"
hyper = { version = "1.1.0", default-features = false, features = ["http1", "http2", "client", "server"] }
hyper-util = { version = "0.1", features = ["http1", "http2", "client", "client-legacy", "server-auto", "tokio"] }
hyper-util = { version = "0.1.3", features = ["http1", "http2", "client", "client-legacy", "server-auto", "tokio"] }
serde = { version = "1.0", features = ["derive"] }
libflate = "1.0"
brotli_crate = { package = "brotli", version = "3.3.0" }
libflate = "2.1"
brotli_crate = { package = "brotli", version = "6.0.0" }
zstd_crate = { package = "zstd", version = "0.13" }
doc-comment = "0.3"
tokio = { version = "1.0", default-features = false, features = ["macros", "rt-multi-thread"] }
futures-util = { version = "0.3.0", default-features = false, features = ["std", "alloc"] }
futures-util = { version = "0.3.28", default-features = false, features = ["std", "alloc"] }
rustls = { version = "0.23", default-features = false, features = ["ring"] }

[target.'cfg(windows)'.dependencies]
winreg = "0.52.0"
windows-registry = "0.2"

[target.'cfg(target_os = "macos")'.dependencies]
system-configuration = { version = "0.5.1", optional = true }
system-configuration = { version = "0.6.0", optional = true }

# wasm

[target.'cfg(target_arch = "wasm32")'.dependencies]
js-sys = "0.3.45"
serde_json = "1.0"
wasm-bindgen = "0.2.68"
wasm-bindgen = "0.2.89"
wasm-bindgen-futures = "0.4.18"
wasm-streams = { version = "0.4", optional = true }

[target.'cfg(target_arch = "wasm32")'.dependencies.web-sys]
version = "0.3.25"
version = "0.3.28"
features = [
"AbortController",
"AbortSignal",
Expand All @@ -210,9 +216,12 @@ features = [
]

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
wasm-bindgen = { version = "0.2.68", features = ["serde-serialize"] }
wasm-bindgen = { version = "0.2.89", features = ["serde-serialize"] }
wasm-bindgen-test = "0.3"

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(reqwest_unstable)'] }

[[example]]
name = "blocking"
path = "examples/blocking.rs"
Expand Down
30 changes: 23 additions & 7 deletions src/async_impl/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pin_project! {
}

/// Converts any `impl Body` into a `impl Stream` of just its DATA frames.
#[cfg(any(feature = "stream", feature = "multipart",))]
pub(crate) struct DataStream<B>(pub(crate) B);

impl Body {
Expand Down Expand Up @@ -88,7 +89,7 @@ impl Body {
#[cfg_attr(docsrs, doc(cfg(feature = "stream")))]
pub fn wrap_stream<S>(stream: S) -> Body
where
S: futures_core::stream::TryStream + Send + Sync + 'static,
S: futures_core::stream::TryStream + Send + 'static,
S::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
Bytes: From<S::Ok>,
{
Expand All @@ -98,19 +99,19 @@ impl Body {
#[cfg(any(feature = "stream", feature = "multipart", feature = "blocking"))]
pub(crate) fn stream<S>(stream: S) -> Body
where
S: futures_core::stream::TryStream + Send + Sync + 'static,
S: futures_core::stream::TryStream + Send + 'static,
S::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
Bytes: From<S::Ok>,
{
use futures_util::TryStreamExt;
use http_body::Frame;
use http_body_util::StreamBody;

let body = http_body_util::BodyExt::boxed(StreamBody::new(
let body = http_body_util::BodyExt::boxed(StreamBody::new(sync_wrapper::SyncStream::new(
stream
.map_ok(|d| Frame::data(Bytes::from(d)))
.map_err(Into::into),
));
)));
Body {
inner: Inner::Streaming(body),
}
Expand Down Expand Up @@ -394,11 +395,25 @@ where
pub(crate) type ResponseBody =
http_body_util::combinators::BoxBody<Bytes, Box<dyn std::error::Error + Send + Sync>>;

pub(crate) fn response(
body: hyper::body::Incoming,
pub(crate) fn boxed<B>(body: B) -> ResponseBody
where
B: hyper::body::Body<Data = Bytes> + Send + Sync + 'static,
B::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
{
use http_body_util::BodyExt;

body.map_err(box_err).boxed()
}

pub(crate) fn response<B>(
body: B,
deadline: Option<Pin<Box<Sleep>>>,
read_timeout: Option<Duration>,
) -> ResponseBody {
) -> ResponseBody
where
B: hyper::body::Body<Data = Bytes> + Send + Sync + 'static,
B::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
{
use http_body_util::BodyExt;

match (deadline, read_timeout) {
Expand All @@ -421,6 +436,7 @@ where

// ===== impl DataStream =====

#[cfg(any(feature = "stream", feature = "multipart",))]
impl<B> futures_core::Stream for DataStream<B>
where
B: HttpBody<Data = Bytes> + Unpin,
Expand Down
Loading

0 comments on commit 9452f57

Please sign in to comment.