feat(client): add a new Client struct with super powers

- Includes ergonomic traits like IntoUrl and IntoBody, allowing easy
usage.
- Client can have a RedirectPolicy.
- Client can have a SslVerifier.

Updated benchmarks for client. (Disabled rust-http client bench since it
hangs.)
This commit is contained in:
Sean McArthur
2014-10-17 14:59:01 -07:00
parent 9e99c57fa8
commit 8c83a3358e
13 changed files with 505 additions and 89 deletions

View File

@@ -4,8 +4,7 @@ use std::os;
use std::io::stdout;
use std::io::util::copy;
use hyper::Url;
use hyper::client::Request;
use hyper::Client;
fn main() {
let args = os::args();
@@ -17,26 +16,17 @@ fn main() {
}
};
let url = match Url::parse(args[1].as_slice()) {
Ok(url) => {
println!("GET {}...", url)
url
},
Err(e) => panic!("Invalid URL: {}", e)
};
let url = &*args[1];
let mut client = Client::new();
let req = match Request::get(url) {
Ok(req) => req,
let mut res = match client.get(url).send() {
Ok(res) => res,
Err(err) => panic!("Failed to connect: {}", err)
};
let mut res = req
.start().unwrap() // failure: Error writing Headers
.send().unwrap(); // failure: Error reading Response head.
println!("Response: {}", res.status);
println!("{}", res.headers);
println!("Headers:\n{}", res.headers);
match copy(&mut res, &mut stdout()) {
Ok(..) => (),
Err(e) => panic!("Stream failure: {}", e)