Skip to content

Commit 6805944

Browse files
committed
feat(crates-io): expose headers for ResponseError::Api
In response to RFC 3231 [^1], our registry client need to return headers to caller, so that the caller (cargo binary) can continue parsing challenge headers. [^1]: https://rust-lang.github.io/rfcs/3231-cargo-asymmetric-tokens.html#the-authentication-process
1 parent 1b15556 commit 6805944

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ cargo-util = { version = "0.2.5", path = "crates/cargo-util" }
2727
cargo_metadata = "0.14.0"
2828
clap = "4.2.0"
2929
core-foundation = { version = "0.9.0", features = ["mac_os_10_7_support"] }
30-
crates-io = { version = "0.37.0", path = "crates/crates-io" }
30+
crates-io = { version = "0.38.0", path = "crates/crates-io" }
3131
criterion = { version = "0.5.1", features = ["html_reports"] }
3232
curl = "0.4.44"
3333
curl-sys = "0.4.63"

crates/crates-io/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "crates-io"
3-
version = "0.37.0"
3+
version = "0.38.0"
44
edition.workspace = true
55
license.workspace = true
66
repository = "https://github.com/rust-lang/cargo"

crates/crates-io/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ pub enum ResponseError {
130130
Curl(curl::Error),
131131
Api {
132132
code: u32,
133+
headers: Vec<String>,
133134
errors: Vec<String>,
134135
},
135136
Code {
@@ -155,7 +156,7 @@ impl fmt::Display for ResponseError {
155156
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
156157
match self {
157158
ResponseError::Curl(e) => write!(f, "{}", e),
158-
ResponseError::Api { code, errors } => {
159+
ResponseError::Api { code, errors, .. } => {
159160
f.write_str("the remote server responded with an error")?;
160161
if *code != 200 {
161162
write!(f, " (status {} {})", code, reason(*code))?;
@@ -447,7 +448,7 @@ impl Registry {
447448

448449
match (self.handle.response_code()?, errors) {
449450
(0, None) | (200, None) => Ok(body),
450-
(code, Some(errors)) => Err(ResponseError::Api { code, errors }),
451+
(code, Some(errors)) => Err(ResponseError::Api { code, headers, errors }),
451452
(code, None) => Err(ResponseError::Code {
452453
code,
453454
headers,

0 commit comments

Comments
 (0)