add some benches with other http libs
This commit is contained in:
@@ -5,17 +5,21 @@ use std::io::{IoResult};
|
||||
use std::io::util::copy;
|
||||
use std::io::net::ip::Ipv4Addr;
|
||||
|
||||
use hyper::method::{Get, Post};
|
||||
use hyper::{Get, Post};
|
||||
use hyper::server::{Server, Handler, Request, Response};
|
||||
use hyper::header::ContentLength;
|
||||
|
||||
struct Echo;
|
||||
|
||||
impl Handler for Echo {
|
||||
fn handle(&mut self, mut req: Request, mut res: Response) -> IoResult<()> {
|
||||
match &req.uri {
|
||||
&hyper::uri::AbsolutePath(ref path) => match (&req.method, path.as_slice()) {
|
||||
match req.uri {
|
||||
hyper::uri::AbsolutePath(ref path) => match (&req.method, path.as_slice()) {
|
||||
(&Get, "/") | (&Get, "/echo") => {
|
||||
try!(res.write_str("Try POST /echo"));
|
||||
let out = b"Try POST /echo";
|
||||
|
||||
res.headers.set(ContentLength(out.len()));
|
||||
try!(res.write(out));
|
||||
return res.end();
|
||||
},
|
||||
(&Post, "/echo") => (), // fall through, fighting mutable borrows
|
||||
@@ -27,14 +31,12 @@ impl Handler for Echo {
|
||||
_ => return res.end()
|
||||
};
|
||||
|
||||
println!("copying...");
|
||||
try!(copy(&mut req, &mut res));
|
||||
println!("copied...");
|
||||
res.end()
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let server = Server::http(Ipv4Addr(127, 0, 0, 1), 1337);
|
||||
server.listen(Echo);
|
||||
server.listen(Echo).unwrap();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user