Skip to content

Commit aa3f57d

Browse files
committed
Updated examples and benchmarks for new Response representation.
1 parent 27df121 commit aa3f57d

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

benches/client.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![feature(macro_rules)]
12
extern crate curl;
23
extern crate http;
34
extern crate hyper;
@@ -13,10 +14,19 @@ fn listen() -> hyper::server::Listening {
1314
server.listen(handle).unwrap()
1415
}
1516

17+
macro_rules! try_continue(
18+
($e:expr) => {{
19+
match $e {
20+
Ok(v) => v,
21+
Err(..) => continue
22+
}
23+
}})
24+
1625
fn handle(mut incoming: Incoming) {
17-
for (_, mut res) in incoming {
18-
res.write(b"Benchmarking hyper vs others!").unwrap();
19-
res.end().unwrap();
26+
for (_, res) in incoming {
27+
let mut res = try_continue!(res.start());
28+
try_continue!(res.write(b"Benchmarking hyper vs others!"))
29+
try_continue!(res.end());
2030
}
2131
}
2232

examples/server.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,25 @@ impl Handler for Echo {
3030
let out = b"Try POST /echo";
3131

3232
res.headers.set(ContentLength(out.len()));
33+
let mut res = try_continue!(res.start());
3334
try_continue!(res.write(out));
3435
try_continue!(res.end());
3536
continue;
3637
},
3738
(&Post, "/echo") => (), // fall through, fighting mutable borrows
3839
_ => {
3940
res.status = hyper::status::NotFound;
40-
try_continue!(res.end());
41+
try_continue!(res.start().and_then(|res| res.end()));
4142
continue;
4243
}
4344
},
4445
_ => {
45-
try_continue!(res.end());
46-
continue;
46+
try_continue!(res.start().and_then(|res| res.end()));
47+
continue;
4748
}
4849
};
4950

51+
let mut res = try_continue!(res.start());
5052
try_continue!(copy(&mut req, &mut res));
5153
try_continue!(res.end());
5254
}

0 commit comments

Comments
 (0)