Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite the API to more closely bind libcurl #105

Merged
merged 72 commits into from
May 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
634868d
Add ctest verification, fill out sys bindings
alexcrichton Mar 30, 2016
e489390
Update travis config and add appveyor
alexcrichton Mar 30, 2016
1fac049
Only build curl-sys for now on travis/appveyor
alexcrichton Mar 30, 2016
f0d9016
Try to fix the windows build
alexcrichton Mar 31, 2016
a1a55f2
Try to fix tests on travis
alexcrichton Mar 31, 2016
ecc9f57
Fix compile of curl crate
alexcrichton Mar 31, 2016
63f8a9e
Fill out the error module
alexcrichton Mar 31, 2016
4fce358
Try to fix travis again
alexcrichton Mar 31, 2016
2a87a2b
Run the full test suite
alexcrichton Mar 31, 2016
81cd4b9
Add bindings to version information.
alexcrichton Mar 31, 2016
7aca2f2
Start filling out raw Easy bindings
alexcrichton Apr 20, 2016
099290c
Apparently QSOSSL isn't on OSX
alexcrichton Apr 26, 2016
819571c
Fix systest (don't have types __enum_ty)
alexcrichton Apr 26, 2016
a6533fa
Work with headers out of order in tests
alexcrichton Apr 26, 2016
bfebe8f
Try to debug travis more
alexcrichton Apr 26, 2016
4536a2c
Remove erroneous src/main.rs
alexcrichton Apr 26, 2016
95a2686
Compat with older curl
alexcrichton Apr 26, 2016
ed8b43a
Comment out XFERINFO for now
alexcrichton Apr 26, 2016
16f90d3
Add a dedicated build for bundled build
alexcrichton Apr 26, 2016
43b2bfd
Handle 0-length url decode/encode
alexcrichton Apr 26, 2016
0d3aecb
Try to make tests more robust?
alexcrichton Apr 26, 2016
a4dd524
Ok, debug again on travis
alexcrichton Apr 26, 2016
b3c191e
What is wrong with OSX
alexcrichton Apr 26, 2016
ad76dd2
Try to fix segfaults on OSX
alexcrichton Apr 26, 2016
bddd368
Re-enable tests
alexcrichton Apr 26, 2016
d2ded3e
Try to fix Appveyor CI
alexcrichton Apr 28, 2016
a046651
Add submodule init to build script
alexcrichton Apr 28, 2016
3439cb9
Tweak what CI is run
alexcrichton Apr 28, 2016
b67a63a
Install gcc-multilib on travis
alexcrichton Apr 28, 2016
1e49136
Try to install 32-bit libssl
alexcrichton Apr 28, 2016
596267e
Only install linux apt packages on 32-bit builds
alexcrichton Apr 28, 2016
22c2464
Help debug test failures
alexcrichton Apr 28, 2016
692aa07
Let's rediscover why `make install` is bad
alexcrichton Apr 28, 2016
2beeb9b
Attempt to appease MSVC
alexcrichton Apr 29, 2016
62c34d1
Print link-paths to curl with pkg-config
alexcrichton Apr 29, 2016
58e020b
Don't run pkg-config on Windows
alexcrichton Apr 29, 2016
3ce0e54
Bump default test timeout
alexcrichton Apr 29, 2016
4d84884
Add a few getters
alexcrichton May 10, 2016
25d8a09
Flesh out more of the accessors
alexcrichton May 10, 2016
d58e84d
Add some simple tests
alexcrichton May 10, 2016
fa7f82c
Display error codes as well
alexcrichton May 10, 2016
30cdee2
Upgrade curl submodule
alexcrichton May 10, 2016
a10148d
Disable more protocols
alexcrichton May 10, 2016
37b8f47
Don't expose curl_httppost bindings for now
alexcrichton May 10, 2016
9fa64ed
Fix test across multiple curl versions
alexcrichton May 10, 2016
b90d77b
Try to fix more MinGW weirdness
alexcrichton May 10, 2016
1b2677f
Clean out old and unused files
alexcrichton May 10, 2016
17f9e0f
Remove stray comment
alexcrichton May 10, 2016
241b0a4
Add a function to reset the lifetime
alexcrichton May 10, 2016
b00e6b5
Update curl submodule again
alexcrichton May 10, 2016
7434131
Use std::panic and test on beta for now
alexcrichton May 10, 2016
2c8d8cf
Add a test where the main thread panics
alexcrichton May 10, 2016
3293678
Add some crate docs
alexcrichton May 10, 2016
4ed9f4a
Add a whole bunch more Easy docs
alexcrichton May 10, 2016
3695aa1
Configure cainfo/capath by default
alexcrichton May 10, 2016
f9fc980
Try using rustup on appveyor
alexcrichton May 11, 2016
5ffc8c6
Continue fighting with appveyor
alexcrichton May 11, 2016
416a7d0
Let's debug appveyor
alexcrichton May 11, 2016
5517754
Update README examples
alexcrichton May 11, 2016
793d14a
Pass --target to rustdoc --test
alexcrichton May 11, 2016
3ccfc62
Ok, don't test the README
alexcrichton May 11, 2016
c44f24a
Perform default configuration on reset()
alexcrichton May 12, 2016
6e658ee
Merge remote-tracking branch 'alex/master' into rewrite
May 13, 2016
9f38b6d
Add private pointer storage
alexcrichton May 12, 2016
9183f80
Tweak the README again
alexcrichton May 12, 2016
03a417e
Improve error message of failed programs
alexcrichton May 12, 2016
a6d0480
Clean up curl-sys Cargo.toml
alexcrichton May 12, 2016
2c1e524
Bump versions
alexcrichton May 12, 2016
ae8ac07
Update curl-sys requirement
alexcrichton May 12, 2016
ccf35d3
Don't expose private for now
alexcrichton May 12, 2016
6106d34
Don't take functions by reference
May 13, 2016
72f5a88
Don't expose duphandle, doesn't seem safe for now
May 13, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 51 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,54 @@
language: rust
matrix:
include:
- os: linux
rust: beta
env: TARGET=x86_64-unknown-linux-gnu
- os: linux
rust: beta
env: TARGET=i686-unknown-linux-gnu
addons:
apt:
packages:
- gcc-multilib
- libssl-dev:i386
- os: linux
rust: beta
env: TARGET=x86_64-unknown-linux-gnu LIBCURL_NO_PKG_CONFIG=1
- os: linux
rust: beta
env: TARGET=i686-unknown-linux-gnu LIBCURL_NO_PKG_CONFIG=1
addons:
apt:
packages:
- gcc-multilib
- libssl-dev:i386
- os: osx
rust: beta
env: TARGET=x86_64-apple-darwin
- os: osx
rust: beta
env: TARGET=i686-apple-darwin
# - os: linux
# rust: beta
# env: TARGET=x86_64-unknown-linux-gnu
- os: linux
rust: nightly
env: TARGET=x86_64-unknown-linux-gnu
sudo: false
rust:
- stable

os:
- linux

before_script:
- pip install 'travis-cargo<0.2' --user && export PATH=$HOME/.local/bin:$PATH
- curl https://static.rust-lang.org/rustup.sh |
sh -s -- --add-target=$TARGET --disable-sudo -y --prefix=`rustc --print sysroot`
script:
- cargo test
- export CARGO_TARGET_DIR=`pwd`/target
- curl --version
- cargo test --target $TARGET
- cargo run --manifest-path systest/Cargo.toml --target $TARGET
- cargo doc --no-deps --target $TARGET
- cargo doc --no-deps -p curl-sys --target $TARGET
after_success:
- travis-cargo --only nightly doc-upload
notifications:
email:
on_success: never
52 changes: 4 additions & 48 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,61 +1,17 @@
[package]

name = "curl"
version = "0.2.19"
authors = ["Carl Lerche <me@carllerche.com>"]
version = "0.3.0"
authors = ["Carl Lerche <me@carllerche.com>",
"Alex Crichton <alex@alexcrichton.com>"]
license = "MIT"
repository = "https://github.com/carllerche/curl-rust"
description = "Rust bindings to libcurl for making HTTP requests"

[dependencies]
url = ">= 0.5, < 2.0"
log = "0.3.0"
libc = "0.2"
curl-sys = { path = "curl-sys", version = "0.1.0" }

[dev-dependencies]
env_logger = "0.3.0"
curl-sys = { path = "curl-sys", version = "0.2.0" }

# Unix platforms use OpenSSL for now to provide SSL functionality
[target."cfg(all(unix, not(target_os = \"macos\")))".dependencies]
openssl-sys = "0.7.0"

[target.i686-unknown-linux-gnu.dependencies]
openssl-sys = "0.7.0"
[target.i586-unknown-linux-gnu.dependencies]
openssl-sys = "0.7.0"
[target.i686-linux-android.dependencies]
openssl-sys = "0.7.0"
[target.x86_64-unknown-linux-gnu.dependencies]
openssl-sys = "0.7.0"
[target.x86_64-unknown-linux-musl.dependencies]
openssl-sys = "0.7.0"
[target.arm-unknown-linux-gnueabihf.dependencies]
openssl-sys = "0.7.0"
[target.armv7-unknown-linux-gnueabihf.dependencies]
openssl-sys = "0.7.0"
[target.arm-linux-androideabi.dependencies]
openssl-sys = "0.7.0"
[target.aarch64-unknown-linux-gnu.dependencies]
openssl-sys = "0.7.0"
[target.powerpc-unknown-linux-gnu.dependencies]
openssl-sys = "0.7.0"
[target.powerpc64-unknown-linux-gnu.dependencies]
openssl-sys = "0.7.0"
[target.powerpc64le-unknown-linux-gnu.dependencies]
openssl-sys = "0.7.0"
[target.i686-unknown-freebsd.dependencies]
openssl-sys = "0.7.0"
[target.x86_64-unknown-freebsd.dependencies]
openssl-sys = "0.7.0"
[target.x86_64-unknown-bitrig.dependencies]
openssl-sys = "0.7.0"
[target.x86_64-unknown-openbsd.dependencies]
openssl-sys = "0.7.0"
[target.x86_64-unknown-dragonfly.dependencies]
openssl-sys = "0.7.0"

[[test]]

name = "test"
path = "test/test.rs"
106 changes: 80 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,66 +1,120 @@
# Curl-Rust
# curl-rust

libcurl bindings for Rust. **This project is in active development and
could (will probably) break API compatibility at any time**.
libcurl bindings for Rust

[![Build Status](https://travis-ci.org/carllerche/curl-rust.svg?branch=master)](https://travis-ci.org/carllerche/curl-rust)
[![crates.io](http://meritbadge.herokuapp.com/mio)](https://crates.io/crates/curl)
[![Build Status](https://travis-ci.org/alexcrichton/curl-rust.svg?branch=master)](https://travis-ci.org/alexcrichton/curl-rust)
[![Build status](https://ci.appveyor.com/api/projects/status/lx98wtbxhhhajpr9?svg=true)](https://ci.appveyor.com/project/alexcrichton/curl-rust)

[Documentation](http://alexcrichton.com/curl-rust)

## Quick Start

```rust
extern crate curl;

use curl::http;
use curl::easy::Easy;

pub fn main() {
let resp = http::handle()
.get("http://www.example.com")
.exec().unwrap();
// Print a web page onto stdout
fn main() {
let mut easy = Easy::new();
easy.url("https://www.rust-lang.org/").unwrap();
easy.perform().unwrap();

println!("code={}; headers={:?}; body={:?}",
resp.get_code(), resp.get_headers(), resp.get_body());
println!("{}", easy.response_code().unwrap());
}
```

Response header names are automatically lower cased.
```rust
extern crate curl;

use curl::easy::Easy;

// Capture output into a local `Vec`.
fn main() {
let mut dst = Vec::new();
let mut write = |data: &[u8]| {
dst.extend_from_slice(data);
data.len()
};
let mut easy = Easy::new();
easy.url("https://www.rust-lang.org/").unwrap();
easy.write_function(&mut write).unwrap();
easy.perform().unwrap();
}
```

## Post / Put requests

Both of these methods expect that a request body is provided. A request
body can be a `&[u8]`, `&str`, or `&Reader`. For example:

```rust
let resp = http::handle()
.post("http://www.example.com/upload", "this is the body")
.exec().unwrap();
```rust,no_run
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.read_function(|buf| {
data.read(buf).unwrap_or(0)
}).unwrap();
easy.post(true).unwrap();
easy.perform().unwrap();
}
```

## Custom headers

Custom headers can be specified as part of the request:

```rust
http::handle()
.get("http://www.example.com")
.header("Authorization", "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==")
.exec();
```rust,no_run
extern crate curl;

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

fn main() {
let mut list = List::new();
list.append("Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==").unwrap();

let mut easy = Easy::new();
easy.url("http://www.example.com").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.

```rust
let handle = http::handle();
```rust,no_run
extern crate curl;

let resp1 = handle.get("http://www.example.com/foo").exec().unwrap();
let resp2 = handle.get("http://www.example.com/bar").exec().unwrap();
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();
}
```

## 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.
41 changes: 41 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
environment:
matrix:
- TARGET: i686-pc-windows-gnu
MINGW_URL: https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/4.9.2/threads-win32/dwarf/i686-4.9.2-release-win32-dwarf-rt_v4-rev4.7z/download
MINGW_ARCHIVE: i686-4.9.2-release-win32-dwarf-rt_v4-rev4.7z
MINGW_DIR: mingw32
- TARGET: x86_64-pc-windows-gnu
MSYS_BITS: 64
- TARGET: i686-pc-windows-msvc
- TARGET: x86_64-pc-windows-msvc

install:
# Install rust, x86_64-pc-windows-msvc host
- curl -sSf -o rustup-init.exe https://win.rustup.rs/
- rustup-init.exe -y
- set PATH=%PATH%;C:\Users\appveyor\.cargo\bin
- rustup update beta-x86_64-pc-windows-msvc
- rustup default beta-x86_64-pc-windows-msvc

# Install the target we're compiling for
- if NOT "%TARGET%" == "x86_64-pc-windows-msvc" rustup target add %TARGET%

# Use the system msys if we can
- if defined MSYS_BITS set PATH=C:\msys64\mingw%MSYS_BITS%\bin;C:\msys64\usr\bin;%PATH%

# download a custom compiler otherwise
- if defined MINGW_ARCHIVE appveyor DownloadFile "%MINGW_URL%" -FileName "%MINGW_ARCHIVE%"
- if defined MINGW_ARCHIVE 7z x -y "%MINGW_ARCHIVE%" > nul
- if defined MINGW_ARCHIVE set PATH=%CD%\%MINGW_DIR%\bin;C:\msys64\usr\bin;%PATH%

# let's see what we got
- where gcc rustc cargo
- rustc -vV
- cargo -vV
- set CARGO_TARGET_DIR=%CD%\target

build: false

test_script:
- cargo test --target %TARGET%
- cargo run --manifest-path systest/Cargo.toml --target %TARGET%
41 changes: 3 additions & 38 deletions curl-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[package]
name = "curl-sys"
version = "0.1.34"
authors = ["Carl Lerche <me@carllerche.com"]
version = "0.2.0"
authors = ["Carl Lerche <me@carllerche.com>",
"Alex Crichton <alex@alexcrichton.com>"]
links = "curl"
build = "build.rs"
license = "MIT"
Expand All @@ -22,39 +23,3 @@ libc = "0.2"

[target."cfg(all(unix, not(target_os = \"macos\")))".dependencies]
openssl-sys = ">= 0"

# Unix platforms use OpenSSL for now to provide SSL functionality
[target.i686-unknown-linux-gnu.dependencies]
openssl-sys = ">= 0"
[target.i586-unknown-linux-gnu.dependencies]
openssl-sys = ">= 0"
[target.i686-linux-android.dependencies]
openssl-sys = ">= 0"
[target.x86_64-unknown-linux-gnu.dependencies]
openssl-sys = ">= 0"
[target.x86_64-unknown-linux-musl.dependencies]
openssl-sys = ">= 0"
[target.arm-unknown-linux-gnueabihf.dependencies]
openssl-sys = ">= 0"
[target.armv7-unknown-linux-gnueabihf.dependencies]
openssl-sys = "0.7.0"
[target.arm-linux-androideabi.dependencies]
openssl-sys = ">= 0"
[target.aarch64-unknown-linux-gnu.dependencies]
openssl-sys = ">= 0"
[target.powerpc-unknown-linux-gnu.dependencies]
openssl-sys = ">= 0"
[target.powerpc64-unknown-linux-gnu.dependencies]
openssl-sys = ">= 0"
[target.powerpc64le-unknown-linux-gnu.dependencies]
openssl-sys = ">= 0"
[target.i686-unknown-freebsd.dependencies]
openssl-sys = ">= 0"
[target.x86_64-unknown-freebsd.dependencies]
openssl-sys = ">= 0"
[target.x86_64-unknown-bitrig.dependencies]
openssl-sys = ">= 0"
[target.x86_64-unknown-openbsd.dependencies]
openssl-sys = ">= 0"
[target.x86_64-unknown-dragonfly.dependencies]
openssl-sys = ">= 0"
Loading