Updated examples and benchmarks for new Response representation.

This commit is contained in:
Jonathan Reem
2014-09-08 14:09:48 -07:00
parent 872dcf758c
commit 13bb07e02d
2 changed files with 18 additions and 11 deletions

View File

@@ -1,3 +1,4 @@
#![feature(macro_rules)]
extern crate curl;
extern crate http;
extern crate hyper;
@@ -13,10 +14,19 @@ fn listen() -> hyper::server::Listening {
server.listen(handle).unwrap()
}
macro_rules! try_continue(
($e:expr) => {{
match $e {
Ok(v) => v,
Err(..) => continue
}
}})
fn handle(mut incoming: Incoming) {
for (_, mut res) in incoming {
res.write(b"Benchmarking hyper vs others!").unwrap();
res.end().unwrap();
for (_, res) in incoming {
let mut res = try_continue!(res.start());
try_continue!(res.write(b"Benchmarking hyper vs others!"))
try_continue!(res.end());
}
}

View File

@@ -29,29 +29,26 @@ impl Handler for Echo {
(&Get, "/") | (&Get, "/echo") => {
let out = b"Try POST /echo";
res.headers.set(ContentLength(out.len()));
res.headers_mut().set(ContentLength(out.len()));
let mut res = try_continue!(res.start());
try_continue!(res.write(out));
try_continue!(res.end());
continue;
},
(&Post, "/echo") => (), // fall through, fighting mutable borrows
_ => {
<<<<<<< Updated upstream
res.status = hyper::status::NotFound;
try_continue!(res.end());
=======
*res.status_mut() = hyper::status::NotFound;
try_continue!(res.start().and_then(|res| res.end()));
>>>>>>> Stashed changes
continue;
}
},
_ => {
try_continue!(res.end());
continue;
try_continue!(res.start().and_then(|res| res.end()));
continue;
}
};
let mut res = try_continue!(res.start());
try_continue!(copy(&mut req, &mut res));
try_continue!(res.end());
}