Skip to content

Commit 4fbd47c

Browse files
committed
Auto merge of #2770 - alexcrichton:new-curl, r=brson
Update to curl 0.3
2 parents 3e70312 + f7d213e commit 4fbd47c

File tree

8 files changed

+136
-96
lines changed

8 files changed

+136
-96
lines changed

Cargo.lock

Lines changed: 8 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,18 @@ path = "src/cargo/lib.rs"
2020
advapi32-sys = "0.1"
2121
crates-io = { path = "src/crates-io", version = "0.4" }
2222
crossbeam = "0.2"
23-
curl = "0.2"
24-
curl-sys = "0.1"
23+
curl = "0.3"
2524
docopt = "0.6"
2625
env_logger = "0.3"
2726
filetime = "0.1"
2827
flate2 = "0.2"
2928
fs2 = "0.2"
3029
git2 = "0.4"
31-
git2-curl = "0.4"
30+
libgit2-sys = "0.4"
31+
git2-curl = "0.5"
3232
glob = "0.2"
3333
kernel32-sys = "0.2"
3434
libc = "0.2"
35-
libgit2-sys = "0.4"
3635
log = "0.3"
3736
num_cpus = "0.2"
3837
regex = "0.1"

src/cargo/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
extern crate crates_io as registry;
77
extern crate crossbeam;
88
extern crate curl;
9-
extern crate curl_sys;
109
extern crate docopt;
1110
extern crate filetime;
1211
extern crate flate2;

src/cargo/ops/registry.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ use std::env;
33
use std::fs::{self, File};
44
use std::iter::repeat;
55
use std::path::{Path, PathBuf};
6+
use std::time::Duration;
67

7-
use curl::http;
8+
use curl::easy::Easy;
89
use git2;
910
use registry::{Registry, NewCrate, NewCrateDependency};
1011
use term::color::BLACK;
@@ -156,24 +157,22 @@ pub fn registry(config: &Config,
156157
}
157158

158159
/// Create a new HTTP handle with appropriate global configuration for cargo.
159-
pub fn http_handle(config: &Config) -> CargoResult<http::Handle> {
160+
pub fn http_handle(config: &Config) -> CargoResult<Easy> {
160161
// The timeout option for libcurl by default times out the entire transfer,
161162
// but we probably don't want this. Instead we only set timeouts for the
162163
// connect phase as well as a "low speed" timeout so if we don't receive
163164
// many bytes in a large-ish period of time then we time out.
164-
let handle = http::handle().timeout(0)
165-
.connect_timeout(30_000 /* milliseconds */)
166-
.low_speed_limit(10 /* bytes per second */)
167-
.low_speed_timeout(30 /* seconds */);
168-
let handle = match try!(http_proxy(config)) {
169-
Some(proxy) => handle.proxy(proxy),
170-
None => handle,
171-
};
172-
let handle = match try!(http_timeout(config)) {
173-
Some(timeout) => handle.connect_timeout(timeout as usize)
174-
.low_speed_timeout((timeout as usize) / 1000),
175-
None => handle,
176-
};
165+
let mut handle = Easy::new();
166+
try!(handle.connect_timeout(Duration::new(30, 0)));
167+
try!(handle.low_speed_limit(10 /* bytes per second */));
168+
try!(handle.low_speed_time(Duration::new(30, 0)));
169+
if let Some(proxy) = try!(http_proxy(config)) {
170+
try!(handle.proxy(&proxy));
171+
}
172+
if let Some(timeout) = try!(http_timeout(config)) {
173+
try!(handle.connect_timeout(Duration::new(timeout as u64, 0)));
174+
try!(handle.low_speed_time(Duration::new(timeout as u64, 0)));
175+
}
177176
Ok(handle)
178177
}
179178

src/cargo/sources/registry.rs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ use std::io::SeekFrom;
164164
use std::io::prelude::*;
165165
use std::path::{PathBuf, Path};
166166

167-
use curl::http;
167+
use curl::easy::Easy;
168168
use flate2::read::GzDecoder;
169169
use git2;
170170
use rustc_serialize::hex::ToHex;
@@ -188,7 +188,7 @@ pub struct RegistrySource<'cfg> {
188188
cache_path: Filesystem,
189189
src_path: Filesystem,
190190
config: &'cfg Config,
191-
handle: Option<http::Handle>,
191+
handle: Option<Easy>,
192192
hashes: HashMap<(String, String), String>, // (name, vers) => cksum
193193
cache: HashMap<String, Vec<(Summary, bool)>>,
194194
updated: bool,
@@ -300,24 +300,34 @@ impl<'cfg> RegistrySource<'cfg> {
300300
self.handle.as_mut().unwrap()
301301
}
302302
};
303-
// TODO: don't download into memory (curl-rust doesn't expose it)
304-
let resp = try!(handle.get(url.to_string()).follow_redirects(true).exec());
305-
if resp.get_code() != 200 && resp.get_code() != 0 {
306-
return Err(internal(format!("failed to get 200 response from {}\n{}",
307-
url, resp)))
303+
// TODO: don't download into memory, but ensure that if we ctrl-c a
304+
// download we should resume either from the start or the middle
305+
// on the next time
306+
try!(handle.get(true));
307+
try!(handle.url(&url.to_string()));
308+
try!(handle.follow_location(true));
309+
let mut state = Sha256::new();
310+
let mut body = Vec::new();
311+
{
312+
let mut handle = handle.transfer();
313+
try!(handle.write_function(|buf| {
314+
state.update(buf);
315+
body.extend_from_slice(buf);
316+
Ok(buf.len())
317+
}));
318+
try!(handle.perform());
319+
}
320+
let code = try!(handle.response_code());
321+
if code != 200 && code != 0 {
322+
bail!("failed to get 200 response from `{}`, got {}", url, code)
308323
}
309324

310325
// Verify what we just downloaded
311-
let actual = {
312-
let mut state = Sha256::new();
313-
state.update(resp.get_body());
314-
state.finish()
315-
};
316-
if actual.to_hex() != expected_hash {
326+
if state.finish().to_hex() != expected_hash {
317327
bail!("failed to verify the checksum of `{}`", pkg)
318328
}
319329

320-
try!(dst.write_all(resp.get_body()));
330+
try!(dst.write_all(&body));
321331
try!(dst.seek(SeekFrom::Start(0)));
322332
Ok(dst)
323333
}

src/cargo/util/errors.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use std::str;
88
use std::string;
99

1010
use curl;
11-
use curl_sys;
1211
use git2;
1312
use rustc_serialize::json;
1413
use semver;
@@ -302,17 +301,13 @@ impl NetworkError for git2::Error {
302301
}
303302
}
304303
}
305-
impl NetworkError for curl::ErrCode {
304+
impl NetworkError for curl::Error {
306305
fn maybe_spurious(&self) -> bool {
307-
match self.code() {
308-
curl_sys::CURLcode::CURLE_COULDNT_CONNECT |
309-
curl_sys::CURLcode::CURLE_COULDNT_RESOLVE_PROXY |
310-
curl_sys::CURLcode::CURLE_COULDNT_RESOLVE_HOST |
311-
curl_sys::CURLcode::CURLE_OPERATION_TIMEDOUT |
312-
curl_sys::CURLcode::CURLE_RECV_ERROR
313-
=> true,
314-
_ => false
315-
}
306+
self.is_couldnt_connect() ||
307+
self.is_couldnt_resolve_proxy() ||
308+
self.is_couldnt_resolve_host() ||
309+
self.is_operation_timedout() ||
310+
self.is_recv_error()
316311
}
317312
}
318313

@@ -334,7 +329,7 @@ from_error! {
334329
git2::Error,
335330
json::DecoderError,
336331
json::EncoderError,
337-
curl::ErrCode,
332+
curl::Error,
338333
CliError,
339334
toml::Error,
340335
url::ParseError,
@@ -360,7 +355,7 @@ impl CargoError for io::Error {}
360355
impl CargoError for git2::Error {}
361356
impl CargoError for json::DecoderError {}
362357
impl CargoError for json::EncoderError {}
363-
impl CargoError for curl::ErrCode {}
358+
impl CargoError for curl::Error {}
364359
impl CargoError for ProcessError {}
365360
impl CargoError for CargoTestError {}
366361
impl CargoError for CliError {}

src/crates-io/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ name = "crates_io"
1313
path = "lib.rs"
1414

1515
[dependencies]
16-
curl = "0.2"
16+
curl = "0.3"
1717
url = "1.0"
1818
rustc-serialize = "0.3"

0 commit comments

Comments
 (0)