Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http3 make request future sync #2339

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ 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.5", optional = true }
h3-quinn = { version = "0.0.6", 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 }
Expand Down
9 changes: 5 additions & 4 deletions src/async_impl/h3_client/connect.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use crate::async_impl::h3_client::dns::resolve;
use crate::dns::DynResolver;
use crate::dns::{resolve, DynResolver};
use crate::error::BoxError;
use bytes::Bytes;
use h3::client::SendRequest;
use h3_quinn::{Connection, OpenStreams};
use http::Uri;
use hyper_util::client::legacy::connect::dns::Name;
use quinn::crypto::rustls::QuicClientConfig;
use quinn::{ClientConfig, Endpoint, TransportConfig};
use std::net::{IpAddr, SocketAddr};
Expand Down Expand Up @@ -58,7 +56,10 @@ impl H3Connector {
// If the host is already an IP address, skip resolving.
vec![SocketAddr::new(addr, port)]
} else {
let addrs = resolve(&mut self.resolver, Name::from_str(host)?).await?;
let name = resolve::Name::from_str(host)?;

let addrs = self.resolver.resolver.resolve(name).await?;

let addrs = addrs.map(|mut addr| {
addr.set_port(port);
addr
Expand Down
43 changes: 0 additions & 43 deletions src/async_impl/h3_client/dns.rs

This file was deleted.

3 changes: 1 addition & 2 deletions src/async_impl/h3_client/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#![cfg(feature = "http3")]

pub(crate) mod connect;
pub(crate) mod dns;
mod pool;

use crate::async_impl::body::ResponseBody;
Expand Down Expand Up @@ -76,7 +75,7 @@ impl H3Client {
}

pub(crate) struct H3ResponseFuture {
inner: Pin<Box<dyn Future<Output = Result<Response<ResponseBody>, Error>> + Send>>,
inner: Pin<Box<dyn Future<Output = Result<Response<ResponseBody>, Error>> + Send + Sync>>,
}

impl Future for H3ResponseFuture {
Expand Down
2 changes: 1 addition & 1 deletion src/async_impl/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ impl RequestBuilder {
/// # Ok(())
/// # }
/// ```
pub fn send(self) -> impl Future<Output = Result<Response, crate::Error>> {
pub fn send(self) -> impl Future<Output = Result<Response, crate::Error>> + Send + Sync {
match self.request {
Ok(req) => self.client.execute_request(req),
Err(err) => Pending::new_err(err),
Expand Down
6 changes: 3 additions & 3 deletions src/dns/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ use std::task::{Context, Poll};
use crate::error::BoxError;

/// Alias for an `Iterator` trait object over `SocketAddr`.
pub type Addrs = Box<dyn Iterator<Item = SocketAddr> + Send>;
pub type Addrs = Box<dyn Iterator<Item = SocketAddr> + Send + Sync>;

/// Alias for the `Future` type returned by a DNS resolver.
pub type Resolving = Pin<Box<dyn Future<Output = Result<Addrs, BoxError>> + Send>>;
pub type Resolving = Pin<Box<dyn Future<Output = Result<Addrs, BoxError>> + Send + Sync>>;

/// Trait for customizing DNS resolution in reqwest.
pub trait Resolve: Send + Sync {
Expand Down Expand Up @@ -53,7 +53,7 @@ impl FromStr for Name {

#[derive(Clone)]
pub(crate) struct DynResolver {
resolver: Arc<dyn Resolve>,
pub(crate) resolver: Arc<dyn Resolve>,
}

impl DynResolver {
Expand Down
21 changes: 13 additions & 8 deletions tests/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,26 @@ async fn http3_request_full() {
});

let url = format!("https://{}/content-length", server.addr());
let res = reqwest::Client::builder()
let res_fut = reqwest::Client::builder()
.http3_prior_knowledge()
.danger_accept_invalid_certs(true)
.build()
.expect("client builder")
.post(url)
.version(http::Version::HTTP_3)
.body("hello")
.send()
.await
.expect("request");
.send();

assert_send_sync(&res_fut);

let res = res_fut.await.expect("request");

assert_eq!(res.version(), http::Version::HTTP_3);
assert_eq!(res.status(), reqwest::StatusCode::OK);
}

fn assert_send_sync<T: Send + Sync>(_: &T) {}

#[tokio::test]
async fn user_agent() {
let server = server::http(move |req| async move {
Expand All @@ -121,14 +125,15 @@ async fn user_agent() {
});

let url = format!("http://{}/ua", server.addr());
let res = reqwest::Client::builder()
let res_fut = reqwest::Client::builder()
.user_agent("reqwest-test-agent")
.build()
.expect("client builder")
.get(&url)
.send()
.await
.expect("request");
.send();

assert_send_sync(&res_fut);
let res = res_fut.await.expect("request");

assert_eq!(res.status(), reqwest::StatusCode::OK);
}
Expand Down
Loading