Upgrade dev-dependencies
This commit is contained in:
committed by
Sean McArthur
parent
47e9f62fb5
commit
4c31a320be
@@ -3,9 +3,9 @@ use http::{Method, Request};
|
||||
use tokio::net::TcpStream;
|
||||
use tokio_rustls::TlsConnector;
|
||||
|
||||
use rustls::Session;
|
||||
use webpki::DNSNameRef;
|
||||
use tokio_rustls::rustls::{OwnedTrustAnchor, RootCertStore, ServerName};
|
||||
|
||||
use std::convert::TryFrom;
|
||||
use std::error::Error;
|
||||
use std::net::ToSocketAddrs;
|
||||
|
||||
@@ -16,9 +16,19 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
|
||||
let _ = env_logger::try_init();
|
||||
|
||||
let tls_client_config = std::sync::Arc::new({
|
||||
let mut c = rustls::ClientConfig::new();
|
||||
c.root_store
|
||||
.add_server_trust_anchors(&webpki_roots::TLS_SERVER_ROOTS);
|
||||
let mut root_store = RootCertStore::empty();
|
||||
root_store.add_server_trust_anchors(webpki_roots::TLS_SERVER_ROOTS.0.iter().map(|ta| {
|
||||
OwnedTrustAnchor::from_subject_spki_name_constraints(
|
||||
ta.subject,
|
||||
ta.spki,
|
||||
ta.name_constraints,
|
||||
)
|
||||
}));
|
||||
|
||||
let mut c = tokio_rustls::rustls::ClientConfig::builder()
|
||||
.with_safe_defaults()
|
||||
.with_root_certificates(root_store)
|
||||
.with_no_client_auth();
|
||||
c.alpn_protocols.push(ALPN_H2.as_bytes().to_owned());
|
||||
c
|
||||
});
|
||||
@@ -33,13 +43,13 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
|
||||
println!("ADDR: {:?}", addr);
|
||||
|
||||
let tcp = TcpStream::connect(&addr).await?;
|
||||
let dns_name = DNSNameRef::try_from_ascii_str("http2.akamai.com").unwrap();
|
||||
let dns_name = ServerName::try_from("http2.akamai.com").unwrap();
|
||||
let connector = TlsConnector::from(tls_client_config);
|
||||
let res = connector.connect(dns_name, tcp).await;
|
||||
let tls = res.unwrap();
|
||||
{
|
||||
let (_, session) = tls.get_ref();
|
||||
let negotiated_protocol = session.get_alpn_protocol();
|
||||
let negotiated_protocol = session.alpn_protocol();
|
||||
assert_eq!(
|
||||
Some(ALPN_H2.as_bytes()),
|
||||
negotiated_protocol.as_ref().map(|x| &**x)
|
||||
|
||||
Reference in New Issue
Block a user