Files
hyper/examples/client.rs
Sean McArthur 64e47b4bbd feat(client): impl Sync for Client
Connector::connect already used &self, and so would require
synchronization to be handled per connector anyway. Adding Sync to the
Client allows users to setup config for a Client once, such as using a
single connection Pool, and then making requests across multiple
threads.

Closes #254

BREAKING CHANGE: Connectors and Protocols passed to the `Client` must
  now also have a `Sync` bounds, but this shouldn't break default usage.
2015-06-12 11:19:54 -07:00

33 lines
631 B
Rust

#![deny(warnings)]
extern crate hyper;
extern crate env_logger;
use std::env;
use std::io;
use hyper::Client;
use hyper::header::Connection;
fn main() {
env_logger::init().unwrap();
let url = match env::args().nth(1) {
Some(url) => url,
None => {
println!("Usage: client <url>");
return;
}
};
let client = Client::new();
let mut res = client.get(&*url)
.header(Connection::close())
.send().unwrap();
println!("Response: {}", res.status);
println!("Headers:\n{}", res.headers);
io::copy(&mut res, &mut io::stdout()).unwrap();
}