Skip to content

Commit

Permalink
Use feature flag when creating Request for hyper and h3 clients
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
  • Loading branch information
kckeiks committed Aug 6, 2022
1 parent 7147457 commit 415c81b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -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"] }
Expand Down
11 changes: 3 additions & 8 deletions examples/h3_simple.rs
Expand Up @@ -11,15 +11,10 @@ async fn main() -> Result<(), reqwest::Error> {
use reqwest::{Client, IntoUrl, Response};

async fn get<T: IntoUrl + Clone>(url: T) -> reqwest::Result<Response> {
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
Expand Down
24 changes: 9 additions & 15 deletions src/async_impl/client.rs
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/async_impl/h3_client/pool.rs
Expand Up @@ -96,6 +96,7 @@ impl PoolClient {
}
}

// TODO: add support for sending data.
pub async fn send_request(&mut self, req: Request<()>) -> Result<Response<Body>, BoxError> {
let mut stream = self.tx.send_request(req).await?;
stream.finish().await?;
Expand Down

0 comments on commit 415c81b

Please sign in to comment.