Skip to content

Commit 13bb07e

Browse files
committed
Updated examples and benchmarks for new Response representation.
1 parent 872dcf7 commit 13bb07e

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
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 & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,26 @@ impl Handler for Echo {
2929
(&Get, "/") | (&Get, "/echo") => {
3030
let out = b"Try POST /echo";
3131

32-
res.headers.set(ContentLength(out.len()));
32+
res.headers_mut().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
_ => {
39-
<<<<<<< Updated upstream
40-
res.status = hyper::status::NotFound;
41-
try_continue!(res.end());
42-
=======
4340
*res.status_mut() = hyper::status::NotFound;
4441
try_continue!(res.start().and_then(|res| res.end()));
45-
>>>>>>> Stashed changes
4642
continue;
4743
}
4844
},
4945
_ => {
50-
try_continue!(res.end());
51-
continue;
46+
try_continue!(res.start().and_then(|res| res.end()));
47+
continue;
5248
}
5349
};
5450

51+
let mut res = try_continue!(res.start());
5552
try_continue!(copy(&mut req, &mut res));
5653
try_continue!(res.end());
5754
}

0 commit comments

Comments
 (0)