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

Restructure API using a handle per stream #12

Merged
merged 19 commits into from
Aug 8, 2017
Merged
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ futures = "0.1"
tokio-io = "0.1"
tokio-timer = "0.1"
bytes = "0.4"
http = { git = "https://github.com/carllerche/http" }
http = { git = "https://github.com/carllerche/http", branch = "uri-try-from-parts" }
byteorder = "1.0"
log = "0.3.8"
fnv = "1.0.5"
Expand Down
51 changes: 31 additions & 20 deletions examples/akamai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,29 @@ extern crate openssl;
extern crate io_dump;
extern crate env_logger;

use h2::client;

use http::request;
use h2::client::Client;

use http::{method, Request};
use futures::*;

use tokio_core::reactor;
use tokio_core::net::TcpStream;

use std::net::ToSocketAddrs;

pub fn main() {
let _ = env_logger::init();

// Sync DNS resolution.
let addr = "http2.akamai.com:443".to_socket_addrs()
.unwrap().next().unwrap();

println!("ADDR: {:?}", addr);

let mut core = reactor::Core::new().unwrap();;
let handle = core.handle();

let tcp = TcpStream::connect(
&"23.39.23.98:443".parse().unwrap(),
&core.handle());
let tcp = TcpStream::connect(&addr, &handle);

let tcp = tcp.then(|res| {
use openssl::ssl::{SslMethod, SslConnectorBuilder};
Expand All @@ -46,24 +52,29 @@ pub fn main() {
// Dump output to stdout
let tls = io_dump::Dump::to_stdout(tls);

client::handshake(tls)
println!("Starting client handshake");
Client::handshake(tls)
})
.then(|res| {
let conn = res.unwrap();
let mut h2 = res.unwrap();

let mut request = request::Head::default();
request.uri = "https://http2.akamai.com/".parse().unwrap();
// request.version = version::H2;
let request = Request::builder()
.method(method::GET)
.uri("https://http2.akamai.com/")
.body(()).unwrap();

conn.send_request(1.into(), request, true)
})
.then(|res| {
let conn = res.unwrap();
// Get the next message
conn.for_each(|frame| {
println!("RX: {:?}", frame);
Ok(())
})
let stream = h2.request(request, true).unwrap();

let stream = stream.and_then(|response| {
let (_, body) = response.into_parts();

body.for_each(|chunk| {
println!("RX: {:?}", chunk);
Ok(())
})
});

h2.join(stream)
})
});

Expand Down
4 changes: 4 additions & 0 deletions examples/client.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/*
extern crate h2;
extern crate http;
extern crate futures;
Expand Down Expand Up @@ -59,3 +60,6 @@ pub fn main() {

core.run(tcp).unwrap();
}
*/

pub fn main() {}
4 changes: 4 additions & 0 deletions examples/server.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/*
extern crate h2;
extern crate http;
extern crate futures;
Expand Down Expand Up @@ -72,3 +73,6 @@ pub fn main() {

core.run(server).unwrap();
}
*/

pub fn main() {}
Loading