The client Request now uses the same system as a server Response to track the write status of headers, and the API has been updated accordingly. Additionally, the Request constructors have been moved onto the Request object instead of being top-level hyper functions, as this better namespaces the client and Server.
46 lines
957 B
Rust
46 lines
957 B
Rust
extern crate hyper;
|
|
|
|
use std::os;
|
|
use std::io::stdout;
|
|
use std::io::util::copy;
|
|
|
|
use hyper::Url;
|
|
use hyper::client::Request;
|
|
|
|
fn main() {
|
|
let args = os::args();
|
|
match args.len() {
|
|
2 => (),
|
|
_ => {
|
|
println!("Usage: client <url>");
|
|
return;
|
|
}
|
|
};
|
|
|
|
let url = match Url::parse(args[1].as_slice()) {
|
|
Ok(url) => {
|
|
println!("GET {}...", url)
|
|
url
|
|
},
|
|
Err(e) => fail!("Invalid URL: {}", e)
|
|
};
|
|
|
|
|
|
let req = match Request::get(url) {
|
|
Ok(req) => req,
|
|
Err(err) => fail!("Failed to connect: {}", err)
|
|
};
|
|
|
|
let mut res = req
|
|
.start().ok().expect("Error writing Headers.")
|
|
.send().ok().expect("Error sending Request.");
|
|
|
|
println!("Response: {}", res.status);
|
|
println!("{}", res.headers);
|
|
match copy(&mut res, &mut stdout()) {
|
|
Ok(..) => (),
|
|
Err(e) => fail!("Stream failure: {}", e)
|
|
};
|
|
|
|
}
|