Add ClientBuilder::h2_prior_knowlege() (#443)
resolves https://github.com/seanmonstar/reqwest/issues/413
This commit is contained in:
committed by
Sean McArthur
parent
021851afd4
commit
6e8e781f8f
@@ -75,6 +75,7 @@ struct Config {
|
||||
identity: Option<Identity>,
|
||||
#[cfg(feature = "tls")]
|
||||
tls: TlsBackend,
|
||||
http2_only: bool,
|
||||
}
|
||||
|
||||
impl ClientBuilder {
|
||||
@@ -104,6 +105,7 @@ impl ClientBuilder {
|
||||
identity: None,
|
||||
#[cfg(feature = "tls")]
|
||||
tls: TlsBackend::default(),
|
||||
http2_only: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -142,10 +144,14 @@ impl ClientBuilder {
|
||||
use ::tls::NoVerifier;
|
||||
|
||||
let mut tls = ::rustls::ClientConfig::new();
|
||||
tls.set_protocols(&[
|
||||
"h2".into(),
|
||||
"http/1.1".into(),
|
||||
]);
|
||||
if config.http2_only {
|
||||
tls.set_protocols(&["h2".into()]);
|
||||
} else {
|
||||
tls.set_protocols(&[
|
||||
"h2".into(),
|
||||
"http/1.1".into(),
|
||||
]);
|
||||
}
|
||||
tls.root_store.add_server_trust_anchors(&webpki_roots::TLS_SERVER_ROOTS);
|
||||
|
||||
if !config.certs_verification {
|
||||
@@ -168,8 +174,11 @@ impl ClientBuilder {
|
||||
Connector::new(proxies.clone())?
|
||||
};
|
||||
|
||||
let hyper_client = ::hyper::Client::builder()
|
||||
.build(connector);
|
||||
let mut builder = ::hyper::Client::builder();
|
||||
if config.http2_only {
|
||||
builder.http2_only(true);
|
||||
}
|
||||
let hyper_client = builder.build(connector);
|
||||
|
||||
let proxies_maybe_http_auth = proxies
|
||||
.iter()
|
||||
@@ -305,6 +314,12 @@ impl ClientBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
/// Only use HTTP/2.
|
||||
pub fn h2_prior_knowledge(mut self) -> ClientBuilder {
|
||||
self.config.http2_only = true;
|
||||
self
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[deprecated(note = "DNS no longer uses blocking threads")]
|
||||
pub fn dns_threads(self, _threads: usize) -> ClientBuilder {
|
||||
|
||||
@@ -293,6 +293,19 @@ impl ClientBuilder {
|
||||
self.inner = func(self.inner);
|
||||
self
|
||||
}
|
||||
|
||||
/// Only use HTTP/2.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// let client = reqwest::Client::builder()
|
||||
/// .h2_prior_knowledge()
|
||||
/// .build().unwrap();
|
||||
/// ```
|
||||
pub fn h2_prior_knowledge(self) -> ClientBuilder {
|
||||
self.with_inner(|inner| inner.h2_prior_knowledge())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user