Updated examples and benchmarks for new Response representation.
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
#![feature(macro_rules)]
|
||||||
extern crate curl;
|
extern crate curl;
|
||||||
extern crate http;
|
extern crate http;
|
||||||
extern crate hyper;
|
extern crate hyper;
|
||||||
@@ -13,10 +14,19 @@ fn listen() -> hyper::server::Listening {
|
|||||||
server.listen(handle).unwrap()
|
server.listen(handle).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! try_continue(
|
||||||
|
($e:expr) => {{
|
||||||
|
match $e {
|
||||||
|
Ok(v) => v,
|
||||||
|
Err(..) => continue
|
||||||
|
}
|
||||||
|
}})
|
||||||
|
|
||||||
fn handle(mut incoming: Incoming) {
|
fn handle(mut incoming: Incoming) {
|
||||||
for (_, mut res) in incoming {
|
for (_, res) in incoming {
|
||||||
res.write(b"Benchmarking hyper vs others!").unwrap();
|
let mut res = try_continue!(res.start());
|
||||||
res.end().unwrap();
|
try_continue!(res.write(b"Benchmarking hyper vs others!"))
|
||||||
|
try_continue!(res.end());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,29 +29,26 @@ impl Handler for Echo {
|
|||||||
(&Get, "/") | (&Get, "/echo") => {
|
(&Get, "/") | (&Get, "/echo") => {
|
||||||
let out = b"Try POST /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.write(out));
|
||||||
try_continue!(res.end());
|
try_continue!(res.end());
|
||||||
continue;
|
continue;
|
||||||
},
|
},
|
||||||
(&Post, "/echo") => (), // fall through, fighting mutable borrows
|
(&Post, "/echo") => (), // fall through, fighting mutable borrows
|
||||||
_ => {
|
_ => {
|
||||||
<<<<<<< Updated upstream
|
|
||||||
res.status = hyper::status::NotFound;
|
|
||||||
try_continue!(res.end());
|
|
||||||
=======
|
|
||||||
*res.status_mut() = hyper::status::NotFound;
|
*res.status_mut() = hyper::status::NotFound;
|
||||||
try_continue!(res.start().and_then(|res| res.end()));
|
try_continue!(res.start().and_then(|res| res.end()));
|
||||||
>>>>>>> Stashed changes
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
try_continue!(res.end());
|
try_continue!(res.start().and_then(|res| res.end()));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mut res = try_continue!(res.start());
|
||||||
try_continue!(copy(&mut req, &mut res));
|
try_continue!(copy(&mut req, &mut res));
|
||||||
try_continue!(res.end());
|
try_continue!(res.end());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user