fixing the akamai example to work with tokio-0.2 (#408)
* fixing the akamai example to work with tokio-0.2 * manually spawn the h2 task to make it go * fix tokio-rustls dependency version
This commit is contained in:
committed by
Sean McArthur
parent
b534a7888a
commit
7615867a5e
@@ -71,7 +71,7 @@ serde_json = "1.0.0"
|
|||||||
# Akamai example
|
# Akamai example
|
||||||
tokio = "=0.2.0-alpha.5"
|
tokio = "=0.2.0-alpha.5"
|
||||||
env_logger = { version = "0.5.3", default-features = false }
|
env_logger = { version = "0.5.3", default-features = false }
|
||||||
rustls = "0.12"
|
rustls = "0.16"
|
||||||
tokio-rustls = "0.5.0"
|
tokio-rustls = "0.12.0-alpha.2"
|
||||||
webpki = "0.18"
|
webpki = "0.21"
|
||||||
webpki-roots = "0.14"
|
webpki-roots = "0.17"
|
||||||
|
|||||||
@@ -1,21 +1,13 @@
|
|||||||
fn main() {
|
|
||||||
// Enable the below code once tokio_rustls moves to std::future
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
use h2::client;
|
use h2::client;
|
||||||
|
|
||||||
use futures::*;
|
|
||||||
use http::{Method, Request};
|
use http::{Method, Request};
|
||||||
|
|
||||||
use tokio::net::TcpStream;
|
use tokio::net::TcpStream;
|
||||||
|
use tokio_rustls::TlsConnector;
|
||||||
|
|
||||||
use rustls::Session;
|
use rustls::Session;
|
||||||
use tokio_rustls::ClientConfigExt;
|
|
||||||
use webpki::DNSNameRef;
|
use webpki::DNSNameRef;
|
||||||
|
|
||||||
use std::net::ToSocketAddrs;
|
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
use std::net::ToSocketAddrs;
|
||||||
|
|
||||||
const ALPN_H2: &str = "h2";
|
const ALPN_H2: &str = "h2";
|
||||||
|
|
||||||
@@ -27,7 +19,7 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
let mut c = rustls::ClientConfig::new();
|
let mut c = rustls::ClientConfig::new();
|
||||||
c.root_store
|
c.root_store
|
||||||
.add_server_trust_anchors(&webpki_roots::TLS_SERVER_ROOTS);
|
.add_server_trust_anchors(&webpki_roots::TLS_SERVER_ROOTS);
|
||||||
c.alpn_protocols.push(ALPN_H2.to_owned());
|
c.alpn_protocols.push(ALPN_H2.as_bytes().to_owned());
|
||||||
c
|
c
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -42,28 +34,42 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
|
|
||||||
let tcp = TcpStream::connect(&addr).await?;
|
let tcp = TcpStream::connect(&addr).await?;
|
||||||
let dns_name = DNSNameRef::try_from_ascii_str("http2.akamai.com").unwrap();
|
let dns_name = DNSNameRef::try_from_ascii_str("http2.akamai.com").unwrap();
|
||||||
let res = tls_client_config.connect_async(dns_name, tcp).await;
|
let connector = TlsConnector::from(tls_client_config);
|
||||||
|
let res = connector.connect(dns_name, tcp).await;
|
||||||
let tls = res.unwrap();
|
let tls = res.unwrap();
|
||||||
{
|
{
|
||||||
let (_, session) = tls.get_ref();
|
let (_, session) = tls.get_ref();
|
||||||
let negotiated_protocol = session.get_alpn_protocol();
|
let negotiated_protocol = session.get_alpn_protocol();
|
||||||
assert_eq!(Some(ALPN_H2), negotiated_protocol.as_ref().map(|x| &**x));
|
assert_eq!(
|
||||||
|
Some(ALPN_H2.as_bytes()),
|
||||||
|
negotiated_protocol.as_ref().map(|x| &**x)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("Starting client handshake");
|
println!("Starting client handshake");
|
||||||
let (mut client, h2) = client::handshake(tls).await?;
|
let (mut client, h2) = client::handshake(tls).await?;
|
||||||
|
|
||||||
|
println!("building request");
|
||||||
let request = Request::builder()
|
let request = Request::builder()
|
||||||
.method(Method::GET)
|
.method(Method::GET)
|
||||||
.uri("https://http2.akamai.com/")
|
.uri("https://http2.akamai.com/")
|
||||||
.body(())
|
.body(())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let (response, _) = client.send_request(request, true).unwrap();
|
println!("sending request");
|
||||||
|
let (response, other) = client.send_request(request, true).unwrap();
|
||||||
|
|
||||||
|
tokio::spawn(async move {
|
||||||
|
if let Err(e) = h2.await {
|
||||||
|
println!("GOT ERR={:?}", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
println!("waiting on response : {:?}", other);
|
||||||
let (_, mut body) = response.await?.into_parts();
|
let (_, mut body) = response.await?.into_parts();
|
||||||
while let Some(chunk) = body.next().await {
|
println!("processing body");
|
||||||
|
while let Some(chunk) = body.data().await {
|
||||||
println!("RX: {:?}", chunk?);
|
println!("RX: {:?}", chunk?);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|||||||
Reference in New Issue
Block a user