Parse url login info into basic auth header
This commit is contained in:
parent
6ca2d02c69
commit
02561b614f
@ -25,6 +25,7 @@ native-tls = "0.2.2"
|
|||||||
num_cpus = "1.10.0"
|
num_cpus = "1.10.0"
|
||||||
failure = "0.1.5"
|
failure = "0.1.5"
|
||||||
failure_derive = "0.1.5"
|
failure_derive = "0.1.5"
|
||||||
|
base64 = "0.10.1"
|
||||||
|
|
||||||
[dependencies.diesel]
|
[dependencies.diesel]
|
||||||
features = ["sqlite", "r2d2"]
|
features = ["sqlite", "r2d2"]
|
||||||
|
|||||||
@ -27,7 +27,7 @@ use hyper::{Body, Client};
|
|||||||
use hyper_tls::HttpsConnector;
|
use hyper_tls::HttpsConnector;
|
||||||
|
|
||||||
use http::header::{
|
use http::header::{
|
||||||
HeaderValue, ETAG, IF_MODIFIED_SINCE, IF_NONE_MATCH, LAST_MODIFIED, LOCATION,
|
HeaderValue, AUTHORIZATION, ETAG, IF_MODIFIED_SINCE, IF_NONE_MATCH, LAST_MODIFIED, LOCATION,
|
||||||
USER_AGENT as USER_AGENT_HEADER,
|
USER_AGENT as USER_AGENT_HEADER,
|
||||||
};
|
};
|
||||||
use http::{Request, Response, StatusCode, Uri};
|
use http::{Request, Response, StatusCode, Uri};
|
||||||
@ -35,6 +35,8 @@ use http::{Request, Response, StatusCode, Uri};
|
|||||||
use futures::future::{loop_fn, Future, Loop};
|
use futures::future::{loop_fn, Future, Loop};
|
||||||
use futures::prelude::*;
|
use futures::prelude::*;
|
||||||
|
|
||||||
|
use base64::{encode_config, URL_SAFE};
|
||||||
|
|
||||||
use crate::database::connection;
|
use crate::database::connection;
|
||||||
use crate::errors::*;
|
use crate::errors::*;
|
||||||
use crate::feed::{Feed, FeedBuilder};
|
use crate::feed::{Feed, FeedBuilder};
|
||||||
@ -276,6 +278,18 @@ impl Source {
|
|||||||
let uri = Uri::from_str(self.uri()).unwrap();
|
let uri = Uri::from_str(self.uri()).unwrap();
|
||||||
let mut req = Request::get(uri).body(Body::empty()).unwrap();
|
let mut req = Request::get(uri).body(Body::empty()).unwrap();
|
||||||
|
|
||||||
|
if let Ok(url) = Url::parse(self.uri()) {
|
||||||
|
if let Some(password) = url.password() {
|
||||||
|
let mut auth = "Basic ".to_owned();
|
||||||
|
auth.push_str(&encode_config(
|
||||||
|
&format!("{}:{}", url.username(), password),
|
||||||
|
URL_SAFE,
|
||||||
|
));
|
||||||
|
req.headers_mut()
|
||||||
|
.insert(AUTHORIZATION, HeaderValue::from_str(&auth).unwrap());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Set the UserAgent cause ppl still seem to check it for some reason...
|
// Set the UserAgent cause ppl still seem to check it for some reason...
|
||||||
req.headers_mut()
|
req.headers_mut()
|
||||||
.insert(USER_AGENT_HEADER, HeaderValue::from_static(USER_AGENT));
|
.insert(USER_AGENT_HEADER, HeaderValue::from_static(USER_AGENT));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user