Skip to content

Instantly share code, notes, and snippets.

@FoundOne
Created October 5, 2016 21:09
Show Gist options
  • Save FoundOne/470766d266eed5ead5908e6cacb7991a to your computer and use it in GitHub Desktop.
Save FoundOne/470766d266eed5ead5908e6cacb7991a to your computer and use it in GitHub Desktop.
extern crate curl;
extern crate futures;
extern crate tokio_core;
extern crate tokio_curl;
#[macro_use]
extern crate log;
extern crate env_logger;
use std::io::{self, Write};
use curl::easy::Easy;
//use futures::Future;
use tokio_core::reactor::Core;
use tokio_curl::Session;
fn main() {
env_logger::init().unwrap();
// Create an event loop that we'll run on, as well as an HTTP `Session`
// which we'll be routing all requests through.
let mut lp = Core::new().unwrap();
let session = Session::new(lp.handle());
// Prepare the HTTP request to be sent.
let mut req = Easy::new();
req.get(true).unwrap();
req.url("https://www.rust-lang.org").unwrap();
req.write_function(|data| {
println!("Printing data:");
io::stdout().write_all(data).unwrap();
Ok(data.len())
}).unwrap();
// Once we've got our session, issue an HTTP request to download the
// rust-lang home page
let request = session.perform(req);
// Execute the request, and print the response code as well as the error
// that happened (if any).
let mut req = lp.run(request).unwrap();
println!("{:?}", req.response_code());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment