From 13bb07e02dd6f9b4028e78badb9664f98a29c237 Mon Sep 17 00:00:00 2001 From: Jonathan Reem Date: Mon, 8 Sep 2014 14:09:48 -0700 Subject: [PATCH] Updated examples and benchmarks for new Response representation. --- benches/client.rs | 16 +++++++++++++--- examples/server.rs | 13 +++++-------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/benches/client.rs b/benches/client.rs index 3694473f..680084f1 100644 --- a/benches/client.rs +++ b/benches/client.rs @@ -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()); } } diff --git a/examples/server.rs b/examples/server.rs index 01ca3b92..ebddbc35 100644 --- a/examples/server.rs +++ b/examples/server.rs @@ -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()); }