From 4a5f526217c13247119329b8228e09352d4ad568 Mon Sep 17 00:00:00 2001 From: Miguel Guarniz Date: Fri, 5 Aug 2022 20:01:43 -0400 Subject: [PATCH] Use feature flag when creating Request for hyper and h3 clients Signed-off-by: Miguel Guarniz --- Cargo.toml | 2 +- examples/h3_simple.rs | 11 +++-------- src/async_impl/client.rs | 24 +++++++++--------------- src/async_impl/h3_client/pool.rs | 1 + 4 files changed, 14 insertions(+), 24 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8868f0195..555500fab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -139,7 +139,7 @@ tokio-socks = { version = "0.5.1", optional = true } ## trust-dns trust-dns-resolver = { version = "0.21", optional = true } -# http3 experimental support +# HTTP/3 experimental support h3 = { git = "https://github.com/hyperium/h3" } h3-quinn = { git = "https://github.com/hyperium/h3" } quinn = { version = "0.8", default-features = false, features = ["tls-rustls", "ring"] } diff --git a/examples/h3_simple.rs b/examples/h3_simple.rs index 29ce8d35d..ba9667f32 100644 --- a/examples/h3_simple.rs +++ b/examples/h3_simple.rs @@ -11,15 +11,10 @@ async fn main() -> Result<(), reqwest::Error> { use reqwest::{Client, IntoUrl, Response}; async fn get(url: T) -> reqwest::Result { - let client = Client::builder() + Client::builder() .http3_prior_knowledge() - .build()?; - - client.get(url.clone()) - .version(Version::HTTP_3) - .send() - .await.unwrap(); - client.get(url) + .build()? + .get(url) .version(Version::HTTP_3) .send() .await diff --git a/src/async_impl/client.rs b/src/async_impl/client.rs index c9ba48595..ada883639 100644 --- a/src/async_impl/client.rs +++ b/src/async_impl/client.rs @@ -1524,29 +1524,23 @@ impl Client { self.proxy_auth(&uri, &mut headers); + let builder = hyper::Request::builder() + .method(method.clone()) + .uri(uri) + .version(version); + let in_flight = match version { #[cfg(feature = "http3")] http::Version::HTTP_3 => { - let mut req = hyper::Request::builder() - .method(method.clone()) - .uri(uri) - .version(version) - .body(()) - .expect("valid request parts"); + let mut req = builder.body(()).expect("valid request parts"); *req.headers_mut() = headers.clone(); ResponseFuture::H3(self.inner.h3_client.request(req)) - } + }, _ => { - let mut req = hyper::Request::builder() - .method(method.clone()) - .uri(uri) - .version(version) - .body(body.into_stream()) - .expect("valid request parts"); - + let mut req = builder.body(body.into_stream()).expect("valid request parts"); *req.headers_mut() = headers.clone(); ResponseFuture::Default(self.inner.hyper.request(req)) - } + }, }; let timeout = timeout diff --git a/src/async_impl/h3_client/pool.rs b/src/async_impl/h3_client/pool.rs index 3cf635834..090ba41c5 100644 --- a/src/async_impl/h3_client/pool.rs +++ b/src/async_impl/h3_client/pool.rs @@ -96,6 +96,7 @@ impl PoolClient { } } + // TODO: add support for sending data. pub async fn send_request(&mut self, req: Request<()>) -> Result, BoxError> { let mut stream = self.tx.send_request(req).await?; stream.finish().await?;