Skip to content

Commit

Permalink
Auto merge of #7389 - alexcrichton:less-winapi-02, r=Eh2406
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Sep 19, 2019
2 parents 3596cb8 + 0f751de commit d3df047
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
1 change: 0 additions & 1 deletion crates/crates-io/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ path = "lib.rs"
[dependencies]
curl = "0.4"
failure = "0.1.1"
http = "0.1"
percent-encoding = "2.0"
serde = { version = "1.0", features = ['derive'] }
serde_derive = "1.0"
Expand Down
59 changes: 56 additions & 3 deletions crates/crates-io/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use std::time::Instant;

use curl::easy::{Easy, List};
use failure::bail;
use http::status::StatusCode;
use percent_encoding::{percent_encode, NON_ALPHANUMERIC};
use serde::{Deserialize, Serialize};
use serde_json;
Expand Down Expand Up @@ -353,8 +352,13 @@ impl Registry {
10MB in size, you can email [email protected] for assistance."
),
(code, Some(errors)) => {
let code = StatusCode::from_u16(code as _)?;
bail!("api errors (status {}): {}", code, errors.join(", "))
let reason = reason(code);
bail!(
"api errors (status {} {}): {}",
code,
reason,
errors.join(", ")
)
}
(code, None) => bail!(
"failed to get a 200 OK response, got {}\n\
Expand All @@ -371,3 +375,52 @@ impl Registry {
Ok(body)
}
}

fn reason(code: u32) -> &'static str {
// Taken from https://developer.mozilla.org/en-US/docs/Web/HTTP/Status
match code {
100 => "Continue",
101 => "Switching Protocol",
103 => "Early Hints",
200 => "OK",
201 => "Created",
202 => "Accepted",
203 => "Non-Authoritative Information",
204 => "No Content",
205 => "Reset Content",
206 => "Partial Content",
300 => "Multiple Choice",
301 => "Moved Permanently",
302 => "Found",
303 => "See Other",
304 => "Not Modified",
307 => "Temporary Redirect",
308 => "Permanent Redirect",
400 => "Bad Request",
401 => "Unauthorized",
402 => "Payment Required",
403 => "Forbidden",
404 => "Not Found",
405 => "Method Not Allowed",
406 => "Not Acceptable",
407 => "Proxy Authentication Required",
408 => "Request Timeout",
409 => "Conflict",
410 => "Gone",
411 => "Length Required",
412 => "Precondition Failed",
413 => "Payload Too Large",
414 => "URI Too Long",
415 => "Unsupported Media Type",
416 => "Request Range Not Satisfiable",
417 => "Expectation Failed",
429 => "Too Many Requests",
431 => "Request Header Fields Too Large",
500 => "Internal Server Error",
501 => "Not Implemented",
502 => "Bad Gateway",
503 => "Service Unavailable",
504 => "Gateway Timeout",
_ => "<unknown>",
}
}

0 comments on commit d3df047

Please sign in to comment.