Skip to content

Commit 0f751de

Browse files
committed
Remove dependency on winapi 0.2
This commit removes Cargo's dependency on `winapi` 0.2 which takes an excessively long time to build, slowing down Windows builds. The `winapi` 0.2 crate was pulled in via a dependency chain that looked like: cargo \- crates-io \- http \- bytes \- iovec \- winapi 0.2 The fix implemented here was to remove the `http` crate dependency from `crates-io` which is only used for rendering status codes, but it's easy enough to inline that function locally.
1 parent eadbaec commit 0f751de

File tree

2 files changed

+56
-4
lines changed

2 files changed

+56
-4
lines changed

crates/crates-io/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ path = "lib.rs"
1616
[dependencies]
1717
curl = "0.4"
1818
failure = "0.1.1"
19-
http = "0.1"
2019
percent-encoding = "2.0"
2120
serde = { version = "1.0", features = ['derive'] }
2221
serde_derive = "1.0"

crates/crates-io/lib.rs

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use std::time::Instant;
99

1010
use curl::easy::{Easy, List};
1111
use failure::bail;
12-
use http::status::StatusCode;
1312
use percent_encoding::{percent_encode, NON_ALPHANUMERIC};
1413
use serde::{Deserialize, Serialize};
1514
use serde_json;
@@ -353,8 +352,13 @@ impl Registry {
353352
10MB in size, you can email [email protected] for assistance."
354353
),
355354
(code, Some(errors)) => {
356-
let code = StatusCode::from_u16(code as _)?;
357-
bail!("api errors (status {}): {}", code, errors.join(", "))
355+
let reason = reason(code);
356+
bail!(
357+
"api errors (status {} {}): {}",
358+
code,
359+
reason,
360+
errors.join(", ")
361+
)
358362
}
359363
(code, None) => bail!(
360364
"failed to get a 200 OK response, got {}\n\
@@ -371,3 +375,52 @@ impl Registry {
371375
Ok(body)
372376
}
373377
}
378+
379+
fn reason(code: u32) -> &'static str {
380+
// Taken from https://developer.mozilla.org/en-US/docs/Web/HTTP/Status
381+
match code {
382+
100 => "Continue",
383+
101 => "Switching Protocol",
384+
103 => "Early Hints",
385+
200 => "OK",
386+
201 => "Created",
387+
202 => "Accepted",
388+
203 => "Non-Authoritative Information",
389+
204 => "No Content",
390+
205 => "Reset Content",
391+
206 => "Partial Content",
392+
300 => "Multiple Choice",
393+
301 => "Moved Permanently",
394+
302 => "Found",
395+
303 => "See Other",
396+
304 => "Not Modified",
397+
307 => "Temporary Redirect",
398+
308 => "Permanent Redirect",
399+
400 => "Bad Request",
400+
401 => "Unauthorized",
401+
402 => "Payment Required",
402+
403 => "Forbidden",
403+
404 => "Not Found",
404+
405 => "Method Not Allowed",
405+
406 => "Not Acceptable",
406+
407 => "Proxy Authentication Required",
407+
408 => "Request Timeout",
408+
409 => "Conflict",
409+
410 => "Gone",
410+
411 => "Length Required",
411+
412 => "Precondition Failed",
412+
413 => "Payload Too Large",
413+
414 => "URI Too Long",
414+
415 => "Unsupported Media Type",
415+
416 => "Request Range Not Satisfiable",
416+
417 => "Expectation Failed",
417+
429 => "Too Many Requests",
418+
431 => "Request Header Fields Too Large",
419+
500 => "Internal Server Error",
420+
501 => "Not Implemented",
421+
502 => "Bad Gateway",
422+
503 => "Service Unavailable",
423+
504 => "Gateway Timeout",
424+
_ => "<unknown>",
425+
}
426+
}

0 commit comments

Comments
 (0)