Merge pull request #52 from Enet4/bug/user-agent-everywhere

Add User-Agent to all requests
This commit is contained in:
Eduardo Pinho 2020-09-30 08:45:31 +01:00 committed by GitHub
commit d54d4f6a2c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 5 deletions

View file

@ -2,7 +2,7 @@ use std::str;
use anyhow::{anyhow, ensure, Error}; use anyhow::{anyhow, ensure, Error};
use futures::{future, Future, IntoFuture, Stream}; use futures::{future, Future, IntoFuture, Stream};
use hyper::{Body, Error as HyperError, Method, Request, Response, Uri}; use hyper::{Body, Error as HyperError, Method, Request, Response, Uri, header::USER_AGENT};
use semver::{Version, VersionReq}; use semver::{Version, VersionReq};
use serde::Deserialize; use serde::Deserialize;
use tokio_service::Service; use tokio_service::Service;
@ -97,7 +97,9 @@ where
let uri = let uri =
try_future_box!(format!("{}/master/{}", CRATES_INDEX_BASE_URI, path).parse::<Uri>()); try_future_box!(format!("{}/master/{}", CRATES_INDEX_BASE_URI, path).parse::<Uri>());
let request = Request::get(uri.clone()).body(Body::empty()).unwrap(); let request = Request::get(uri.clone())
.header(USER_AGENT, "deps.rs")
.body(Body::empty()).unwrap();
Box::new(self.0.call(request).from_err().and_then(move |response| { Box::new(self.0.call(request).from_err().and_then(move |response| {
let status = response.status(); let status = response.status();
@ -170,7 +172,9 @@ where
let uri = format!("{}/summary", CRATES_API_BASE_URI) let uri = format!("{}/summary", CRATES_API_BASE_URI)
.parse::<Uri>() .parse::<Uri>()
.unwrap(); .unwrap();
let request = Request::get(uri.clone()).body(Body::empty()).unwrap(); let request = Request::get(uri.clone())
.header(USER_AGENT, "deps.rs")
.body(Body::empty()).unwrap();
Box::new(service.call(request).from_err().and_then(move |response| { Box::new(service.call(request).from_err().and_then(move |response| {
let status = response.status(); let status = response.status();

View file

@ -1,6 +1,6 @@
use anyhow::{anyhow, ensure, Error}; use anyhow::{anyhow, ensure, Error};
use futures::{Future, Stream}; use futures::{Future, Stream};
use hyper::{Body, Error as HyperError, Method, Request, Response}; use hyper::{Body, Error as HyperError, Method, Request, Response, header::USER_AGENT};
use relative_path::RelativePathBuf; use relative_path::RelativePathBuf;
use tokio_service::Service; use tokio_service::Service;
@ -35,7 +35,9 @@ where
&RepoSite::Bitbucket => try_future_box!(bitbucket::get_manifest_uri(&repo_path, &path)), &RepoSite::Bitbucket => try_future_box!(bitbucket::get_manifest_uri(&repo_path, &path)),
}; };
let request = Request::get(uri.clone()).body(Body::empty()).unwrap(); let request = Request::get(uri.clone())
.header(USER_AGENT, "deps.rs")
.body(Body::empty()).unwrap();
Box::new(self.0.call(request).from_err().and_then(move |response| { Box::new(self.0.call(request).from_err().and_then(move |response| {
let status = response.status(); let status = response.status();