feat(hyper): switch to std::io, std::net, and std::path.

All instances of `old_io` and `old_path` were switched to use the new
shiny `std::io`, `std::net`, and `std::path` modules. This means that
`Request` and `Response` implement `Read` and `Write` now.

Because of the changes to `TcpListener`, this also takes the opportunity
to correct the method usage of `Server`. As with other
languages/frameworks, the server is first created with a handler, and
then a host/port is passed to a `listen` method. This reverses what
`Server` used to do.

Closes #347

BREAKING CHANGE: Check the docs. Everything was touched.
This commit is contained in:
Sean McArthur
2015-02-17 15:29:52 -08:00
parent 7235d3f74a
commit 0fd6fcd7c7
22 changed files with 641 additions and 639 deletions

View File

@@ -1,9 +1,10 @@
#![feature(old_io, test)]
#![feature(io, net, test)]
extern crate hyper;
extern crate test;
use test::Bencher;
use std::old_io::net::ip::Ipv4Addr;
use std::io::{Read, Write};
use std::net::IpAddr;
use hyper::method::Method::Get;
use hyper::server::{Request, Response};
@@ -12,7 +13,8 @@ static PHRASE: &'static [u8] = b"Benchmarking hyper vs others!";
fn request(url: hyper::Url) {
let req = hyper::client::Request::new(Get, url).unwrap();
req.start().unwrap().send().unwrap().read_to_string().unwrap();
let mut s = String::new();
req.start().unwrap().send().unwrap().read_to_string(&mut s).unwrap();
}
fn hyper_handle(_: Request, res: Response) {
@@ -23,8 +25,8 @@ fn hyper_handle(_: Request, res: Response) {
#[bench]
fn bench_hyper(b: &mut Bencher) {
let server = hyper::Server::http(Ipv4Addr(127, 0, 0, 1), 0);
let mut listener = server.listen(hyper_handle).unwrap();
let server = hyper::Server::http(hyper_handle);
let mut listener = server.listen(IpAddr::new_v4(127, 0, 0, 1), 0).unwrap();
let url = hyper::Url::parse(&*format!("http://{}", listener.socket)).unwrap();
b.iter(|| request(url.clone()));