Skip to content

Commit

Permalink
refactor(http_remote): replace cargo challenge scheme with crates-io …
Browse files Browse the repository at this point in the history
…provided one
  • Loading branch information
weihanglo committed Jun 25, 2023
1 parent f75bc82 commit 9ea8341
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 20 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ glob.workspace = true
hex.workspace = true
hmac.workspace = true
home.workspace = true
http-auth.workspace = true
humantime.workspace = true
ignore.workspace = true
im-rc.workspace = true
Expand Down
23 changes: 5 additions & 18 deletions src/cargo/sources/registry/http_remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use crate::util::network::sleep::SleepTracker;
use crate::util::{auth, Config, Filesystem, IntoUrl, Progress, ProgressStyle};
use anyhow::Context;
use cargo_util::paths;
use crates_io::cargo_challenge_from_headers;
use crates_io::Challenge;
use curl::easy::{Easy, List};
use curl::multi::{EasyHandle, Multi};
use log::{debug, trace};
Expand Down Expand Up @@ -550,24 +552,9 @@ impl<'cfg> RegistryData for HttpRegistry<'cfg> {
self.fresh.remove(path);
self.auth_required = true;

// Look for a `www-authenticate` header with the `Cargo` scheme.
for header in &result.header_map.www_authenticate {
for challenge in http_auth::ChallengeParser::new(header) {
match challenge {
Ok(challenge) if challenge.scheme.eq_ignore_ascii_case("Cargo") => {
// Look for the `login_url` parameter.
for (param, value) in challenge.params {
if param.eq_ignore_ascii_case("login_url") {
self.login_url = Some(value.to_unescaped().into_url()?);
}
}
}
Ok(challenge) => {
debug!("ignoring non-Cargo challenge: {}", challenge.scheme)
}
Err(e) => debug!("failed to parse challenge: {}", e),
}
}
let headers = result.header_map.www_authenticate.as_slice();
if let Some(Challenge::Login(url)) = cargo_challenge_from_headers(headers) {
self.login_url = Some(url);
}
}
StatusCode::Unauthorized => {
Expand Down

0 comments on commit 9ea8341

Please sign in to comment.