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,7 @@
#![feature(env, old_io)]
#![feature(env)]
extern crate hyper;
use std::env;
use std::old_io::stdout;
use std::old_io::util::copy;
use hyper::Client;
@@ -18,16 +16,12 @@ fn main() {
let mut client = Client::new();
let mut res = match client.get(&*url).send() {
let res = match client.get(&*url).send() {
Ok(res) => res,
Err(err) => panic!("Failed to connect: {:?}", err)
};
println!("Response: {}", res.status);
println!("Headers:\n{}", res.headers);
match copy(&mut res, &mut stdout()) {
Ok(..) => (),
Err(e) => panic!("Stream failure: {:?}", e)
};
//TODO: add copy back when std::stdio impls std::io::Write.
}

View File

@@ -1,7 +1,8 @@
#![feature(old_io)]
#![feature(io, net)]
extern crate hyper;
use std::old_io::net::ip::Ipv4Addr;
use std::io::Write;
use std::net::IpAddr;
use hyper::server::{Request, Response};
static PHRASE: &'static [u8] = b"Hello World!";
@@ -13,7 +14,7 @@ fn hello(_: Request, res: Response) {
}
fn main() {
let _listening = hyper::Server::http(Ipv4Addr(127, 0, 0, 1), 3000)
.listen(hello).unwrap();
let _listening = hyper::Server::http(hello)
.listen(IpAddr::new_v4(127, 0, 0, 1), 3000).unwrap();
println!("Listening on http://127.0.0.1:3000");
}

View File

@@ -1,9 +1,9 @@
#![feature(old_io)]
#![feature(io, net)]
extern crate hyper;
#[macro_use] extern crate log;
use std::old_io::util::copy;
use std::old_io::net::ip::Ipv4Addr;
use std::io::{Write, copy};
use std::net::IpAddr;
use hyper::{Get, Post};
use hyper::header::ContentLength;
@@ -50,7 +50,7 @@ fn echo(mut req: Request, mut res: Response) {
}
fn main() {
let server = Server::http(Ipv4Addr(127, 0, 0, 1), 1337);
let _guard = server.listen(echo).unwrap();
let server = Server::http(echo);
let _guard = server.listen(IpAddr::new_v4(127, 0, 0, 1), 1337).unwrap();
println!("Listening on http://127.0.0.1:1337");
}