#curl #sys

sys curl-sys

Native bindings to the libcurl library

68 releases

0.4.8 Jul 31, 2018
0.4.5 May 2, 2018
0.4.1 Jan 3, 2018
0.3.15 Sep 19, 2017
0.1.2 Dec 19, 2014
Download history 11135/week @ 2018-05-10 16343/week @ 2018-05-17 13037/week @ 2018-05-24 13429/week @ 2018-05-31 12359/week @ 2018-06-07 11356/week @ 2018-06-14 11411/week @ 2018-06-21 13993/week @ 2018-06-28 15476/week @ 2018-07-05 13973/week @ 2018-07-12 15455/week @ 2018-07-19 15945/week @ 2018-07-26 15903/week @ 2018-08-02

59,936 downloads per month
Used in 159 crates (4 directly)

MIT license

7MB
154K SLoC

C 117K SLoC // 0.2% comments Python 15K SLoC // 0.1% comments Perl 14K SLoC // 0.2% comments D 3K SLoC Batch 1.5K SLoC Rust 1K SLoC // 0.1% comments Shell 1K SLoC // 0.3% comments C++ 493 SLoC // 0.2% comments VBScript 341 SLoC // 0.1% comments

curl-rust

libcurl bindings for Rust

Build Status Build status

Documentation

Quick Start

extern crate curl;

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

use curl::easy::Easy;

// Print a web page onto stdout
fn main() {
    let mut easy = Easy::new();
    easy.url("https://www.rust-lang.org/").unwrap();
    easy.write_function(|data| {
        stdout().write_all(data).unwrap();
        Ok(data.len())
    }).unwrap();
    easy.perform().unwrap();

    println!("{}", easy.response_code().unwrap());
}
extern crate curl;

use curl::easy::Easy;

// Capture output into a local `Vec`.
fn main() {
    let mut dst = Vec::new();
    let mut easy = Easy::new();
    easy.url("https://www.rust-lang.org/").unwrap();

    let mut transfer = easy.transfer();
    transfer.write_function(|data| {
        dst.extend_from_slice(data);
        Ok(data.len())
    }).unwrap();
    transfer.perform().unwrap();
}

Post / Put requests

The put and post methods on Easy can configure the method of the HTTP request, and then read_function can be used to specify how data is filled in. This interface works particularly well with types that implement Read.

extern crate curl;

use std::io::Read;
use curl::easy::Easy;

fn main() {
    let mut data = "this is the body".as_bytes();

    let mut easy = Easy::new();
    easy.url("http://www.example.com/upload").unwrap();
    easy.post(true).unwrap();
    easy.post_field_size(data.len() as u64).unwrap();

    let mut transfer = easy.transfer();
    transfer.read_function(|buf| {
        Ok(data.read(buf).unwrap_or(0))
    }).unwrap();
    transfer.perform().unwrap();
}

Custom headers

Custom headers can be specified as part of the request:

extern crate curl;

use curl::easy::{Easy, List};

fn main() {
    let mut easy = Easy::new();
    easy.url("http://www.example.com").unwrap();

    let mut list = List::new();
    list.append("Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==").unwrap();
    easy.http_headers(list).unwrap();
    easy.perform().unwrap();
}

Keep alive

The handle can be re-used across multiple requests. Curl will attempt to keep the connections alive.

extern crate curl;

use curl::easy::Easy;

fn main() {
    let mut handle = Easy::new();

    handle.url("http://www.example.com/foo").unwrap();
    handle.perform().unwrap();

    handle.url("http://www.example.com/bar").unwrap();
    handle.perform().unwrap();
}

Multiple requests

The libcurl library provides support for sending multiple requests simultaneously through the "multi" interface. This is currently bound in the multi module of this crate and provides the ability to execute multiple transfers simultaneously. For more information, see that module.

Version Support

The bindings have been developed using curl version 7.24.0. They should work with any newer version of curl and possibly with older versions, but this has not been tested.

License

The curl-rust crate is licensed under the MIT license, see LICENSE for more details.

Dependencies

~3MB
~64K SLoC