Skip to content

Commit 6a84a93

Browse files
authored
Merge pull request #12 from carllerche/stream-api
Restructure API using a handle per stream
2 parents d06fb48 + 8a5e0c3 commit 6a84a93

29 files changed

+1926
-816
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ futures = "0.1"
88
tokio-io = "0.1"
99
tokio-timer = "0.1"
1010
bytes = "0.4"
11-
http = { git = "https://github.com/carllerche/http" }
11+
http = { git = "https://github.com/carllerche/http", branch = "uri-try-from-parts" }
1212
byteorder = "1.0"
1313
log = "0.3.8"
1414
fnv = "1.0.5"

examples/akamai.rs

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,29 @@ extern crate openssl;
88
extern crate io_dump;
99
extern crate env_logger;
1010

11-
use h2::client;
12-
13-
use http::request;
11+
use h2::client::Client;
1412

13+
use http::{method, Request};
1514
use futures::*;
1615

1716
use tokio_core::reactor;
1817
use tokio_core::net::TcpStream;
1918

19+
use std::net::ToSocketAddrs;
20+
2021
pub fn main() {
2122
let _ = env_logger::init();
2223

24+
// Sync DNS resolution.
25+
let addr = "http2.akamai.com:443".to_socket_addrs()
26+
.unwrap().next().unwrap();
27+
28+
println!("ADDR: {:?}", addr);
29+
2330
let mut core = reactor::Core::new().unwrap();;
31+
let handle = core.handle();
2432

25-
let tcp = TcpStream::connect(
26-
&"23.39.23.98:443".parse().unwrap(),
27-
&core.handle());
33+
let tcp = TcpStream::connect(&addr, &handle);
2834

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

49-
client::handshake(tls)
55+
println!("Starting client handshake");
56+
Client::handshake(tls)
5057
})
5158
.then(|res| {
52-
let conn = res.unwrap();
59+
let mut h2 = res.unwrap();
5360

54-
let mut request = request::Head::default();
55-
request.uri = "https://http2.akamai.com/".parse().unwrap();
56-
// request.version = version::H2;
61+
let request = Request::builder()
62+
.method(method::GET)
63+
.uri("https://http2.akamai.com/")
64+
.body(()).unwrap();
5765

58-
conn.send_request(1.into(), request, true)
59-
})
60-
.then(|res| {
61-
let conn = res.unwrap();
62-
// Get the next message
63-
conn.for_each(|frame| {
64-
println!("RX: {:?}", frame);
65-
Ok(())
66-
})
66+
let stream = h2.request(request, true).unwrap();
67+
68+
let stream = stream.and_then(|response| {
69+
let (_, body) = response.into_parts();
70+
71+
body.for_each(|chunk| {
72+
println!("RX: {:?}", chunk);
73+
Ok(())
74+
})
75+
});
76+
77+
h2.join(stream)
6778
})
6879
});
6980

examples/client.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/*
12
extern crate h2;
23
extern crate http;
34
extern crate futures;
@@ -59,3 +60,6 @@ pub fn main() {
5960
6061
core.run(tcp).unwrap();
6162
}
63+
*/
64+
65+
pub fn main() {}

examples/server.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/*
12
extern crate h2;
23
extern crate http;
34
extern crate futures;
@@ -72,3 +73,6 @@ pub fn main() {
7273
7374
core.run(server).unwrap();
7475
}
76+
*/
77+
78+
pub fn main() {}

0 commit comments

Comments
 (0)