Crate tokio_curl [] [src]

A Future interface on top of libcurl

This crate provides a futures-based interface to the libcurl HTTP library. Building on top of the curl crate on crates.io, this allows using a battle-tested C library for sending HTTP requests in an asynchronous fashion.

Examples

extern crate curl;
extern crate futures;
extern crate tokio_core;
extern crate tokio_curl;

use std::io::{self, Write};

use curl::easy::Easy;
use futures::Future;
use tokio_core::reactor::Core;
use tokio_curl::Session;

fn main() {
    // 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| {
        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());
}

Platform support

This crate works on both Unix and Windows, but note that it will not scale well on Windows. Unfortunately the implementation (seemingly from libcurl) relies on select, which does not scale very far on Windows.

Structs

Perform

A future returned from the Session::perform method.

PerformError

Error returned by the future returned from perform.

Session

A shared cache for HTTP requests to pool data such as TCP connections between.