mirror of
https://github.com/deps-rs/deps.rs.git
synced 2024-11-22 18:36:30 +00:00
Add User-Agent to all requests from the server
- Required by crates.io, which will otherwise forbid the request - Do the same thing for all other HTTP requests, for consistency and transparency
This commit is contained in:
parent
c6b3fb46e8
commit
7d4c8dd74d
2 changed files with 11 additions and 5 deletions
|
@ -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();
|
||||||
|
|
|
@ -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();
|
||||||
|
|
Loading…
Reference in a new issue