1
0
Fork
You've already forked ratcurl
0
forked from transcast/ratcurl
No description
  • Rust 99.8%
  • Shell 0.2%
2023年01月20日 16:04:51 +01:00
.github/workflows Remove deprecated windows2016 image 2021年12月02日 08:04:37 -08:00
ci Add experimental support for rustls ( #374 ) 2022年01月06日 10:40:27 -06:00
curl-sys mark as linking with "curl-impersonate" instead of "curl" 2023年01月20日 16:04:51 +01:00
examples fork 2023年01月19日 22:55:17 +01:00
src fork 2023年01月19日 22:55:17 +01:00
systest fork 2023年01月19日 22:55:17 +01:00
tests fork 2023年01月19日 22:55:17 +01:00
.gitignore Add an option to set the expect 100 timeout ( #376 ) 2021年02月22日 19:13:49 -06:00
.gitmodules add .git suffix to the submodule url 2019年08月26日 00:45:19 +08:00
build.rs Update OpenSSL initialization check ( #419 ) 2021年11月02日 09:35:13 -05:00
Cargo.toml fork 2023年01月19日 22:55:17 +01:00
LICENSE Improve the README some and add a license 2014年07月02日 13:37:44 -07:00
README.md fork 2023年01月19日 22:55:17 +01:00

ratcurl

libcurl bindings for Rust, with support for curl-impersonate.

fork of [curl-rust]

Latest Version Documentation License Build

quick start

usestd::io::{stdout,Write};useratcurl::easy::Easy;// Print a web page onto stdout
fn main(){letmuteasy=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());}
useratcurl::easy::Easy;// Capture output into a local `Vec`.
fn main(){letmutdst=Vec::new();letmuteasy=Easy::new();easy.url("https://www.rust-lang.org/").unwrap();letmuttransfer=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.

use std::io::Read;
use ratcurl::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:

use ratcurl::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.

use ratcurl::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.

building

by default, this crate will attempt to dynamically link to the system-wide libcurl and the system-wide SSL library. Some of this behavior can be customized with various Cargo features:

  • ssl: Enable SSL/TLS support using the platform-default TLS backend. On Windows this is Schannel, on macOS Secure Transport, and OpenSSL (or equivalent) on all other platforms. Enabled by default.

  • rustls Enable SSL/TLS support via Rustls, a well-received alternative TLS backend written in Rust. Rustls is always statically linked. Disabled by default.

    Note that Rustls support is experimental within Curl itself and may have significant bugs, so we don't offer any sort of stability guarantee with this feature.

  • http2: Enable HTTP/2 support via libnghttp2. Disabled by default.

  • static-curl: Use a bundled libcurl version and statically link to it. Disabled by default.

  • static-ssl: Use a bundled OpenSSL version and statically link to it. Only applies on platforms that use OpenSSL. Disabled by default.

  • spnego: Enable SPNEGO support. Disabled by default.

  • upkeep_7_62_0: Enable curl_easy_upkeep() support, introduced in curl 7.62.0. Disabled by default.

  • poll_7_68_0: Enable curl_multi_poll()/curl_multi_wakeup() support, requires curl 7.68.0 or later. Disabled by default.

  • ntlm: Enable NTLM support in curl. Disabled by default.

  • windows-static-ssl: Enable Openssl support on Windows via the static build provided by vcpkg. Incompatible with ssl (use --no-default-features). Disabled by default.

  • impersonate-chrome: Use curl-impersonate in chrome flavor. Incompatible with static-curl, enforces built-in BoringSSL as TLS backend.

  • impersonate-ff: Use curl-impersonate in firefox flavor. Incompatible with static-curl, enforces built-in NSS as TLS backend.

    Note that to install openssl on windows via vcpkg the following commands needs to be ran:

    git clone https://github.com/microsoft/vcpkg
    cd vcpkg
    ./bootstrap-vcpkg.bat -disableMetrics
    ./vcpkg.exe integrate install
    ./vcpkg.exe install openssl:x64-windows-static-md
    

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.

troubleshooting

curl built against the NSS SSL library

if you encounter the following error message:

 [77] Problem with the SSL CA cert (path? access rights?)

that means most likely, that curl was linked against libcurl-nss.so due to installed libcurl NSS development files, and that the required library libnsspem.so is missing. see also the curl man page: "If curl is built against the NSS SSL library, the NSS PEM PKCS#11 module (libnsspem.so) needs to be available for this option to work properly."

in order to avoid this failure you can either

  • install the missing library (e.g. Debian: nss-plugin-pem), or
  • remove the libcurl NSS development files (e.g. Debian: libcurl4-nss-dev) and rebuild curl-rust.

license

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