Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Invalid headers with crates.io. #103

Closed
ehuss opened this issue May 17, 2019 · 3 comments
Closed

Invalid headers with crates.io. #103

ehuss opened this issue May 17, 2019 · 3 comments

Comments

@ehuss
Copy link

ehuss commented May 17, 2019

The code that downloads from crates.io does not set the appropriate user-agent header. This causes crates.io to reject the request. Something like the following should fix it.

diff --git a/Cargo.toml b/Cargo.toml
index 9183fbf..47e6ed0 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -24,7 +24,8 @@ path = "src/bin/rust_semverver.rs"
 
 [dependencies]
 cargo = "0.32"
-crates-io = "0.20"
+crates-io = "0.23"
+curl = "0.4.21"
 env_logger = "0.6"
 failure = "0.1"
 log = "0.4"
diff --git a/src/bin/cargo_semver.rs b/src/bin/cargo_semver.rs
index 82caf68..6e4ae28 100644
--- a/src/bin/cargo_semver.rs
+++ b/src/bin/cargo_semver.rs
@@ -8,6 +8,7 @@ extern crate serde_derive;
 extern crate serde_json;
 
 use cargo::core::{Package, PackageId, PackageSet, Source, SourceId, SourceMap, Workspace};
+use curl::easy::Easy;
 use log::debug;
 use std::{
     env,
@@ -463,7 +464,10 @@ impl<'a> WorkInfo<'a> {
 ///
 /// If no crate with the exact name is present, error out.
 pub fn find_on_crates_io(crate_name: &str) -> Result<crates_io::Crate> {
-    let mut registry = crates_io::Registry::new("https://crates.io".to_owned(), None);
+    let mut handle = Easy::new();
+    handle.useragent(&format!("rust-semverver {}", env!("CARGO_PKG_VERSION")))?;
+    let mut registry =
+        crates_io::Registry::new_handle("https://crates.io".to_owned(), None, handle);
 
     registry
         .search(crate_name, 1)
@ibabushkin
Copy link
Contributor

Interesting, I never noticed any issues. Are new changes to crates.io the reason, or am I missing something else? Keep in mind, the build is still somewhat broken as of now, so that part of the crate is currently untested.

Regardless, I'll include your suggested changes, thanks alot!

@ehuss
Copy link
Author

ehuss commented May 17, 2019

I believe it was changed about 2 weeks ago: rust-lang/crates.io#1696

@ibabushkin
Copy link
Contributor

ibabushkin commented May 19, 2019

This should be fixed now :), the new version is on crates.io (unrelated bugs wrt trait handling remain though, sadly).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants