Skip to content

Commit

Permalink
Change typed_headers to headers dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
nagua authored and e00E committed Jan 16, 2021
1 parent 81400d7 commit 5b9abef
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ hyper-rustls = { version = "0.22", optional = true }
webpki = { version = "0.21", optional = true }
rustls-native-certs = { version = "0.5.0", optional = true }
webpki-roots = { version = "0.21.0", optional = true }
typed-headers = "0.2"
headers = "0.3"

[dev-dependencies]
tokio = { version = "1.0", features = ["full"] }
tokio = { version = "*", features = ["full"] }
hyper = { version = "*", features = ["client", "http1"] }

[features]
tls = ["tokio-native-tls", "hyper-tls", "native-tls"]
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ use hyper::{Client, Request, Uri};
use hyper::client::HttpConnector;
use futures::{TryFutureExt, TryStreamExt};
use hyper_proxy::{Proxy, ProxyConnector, Intercept};
use typed_headers::Credentials;
use headers::Authorization;
use std::error::Error;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let proxy = {
let proxy_uri = "http://my-proxy:8080".parse().unwrap();
let mut proxy = Proxy::new(Intercept::All, proxy_uri);
proxy.set_authorization(Credentials::basic("John Doe", "Agent1234").unwrap());
proxy.set_authorization(Authorization::basic("John Doe", "Agent1234"));
let connector = HttpConnector::new();
let proxy_connector = ProxyConnector::from_proxy(connector, proxy).unwrap();
proxy_connector
Expand Down
16 changes: 8 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//! use hyper::client::HttpConnector;
//! use futures::{TryFutureExt, TryStreamExt};
//! use hyper_proxy::{Proxy, ProxyConnector, Intercept};
//! use typed_headers::Credentials;
//! use headers::Authorization;
//! use std::error::Error;
//! use tokio::io::{stdout, AsyncWriteExt as _};
//!
Expand All @@ -15,7 +15,7 @@
//! let proxy = {
//! let proxy_uri = "http://my-proxy:8080".parse().unwrap();
//! let mut proxy = Proxy::new(Intercept::All, proxy_uri);
//! proxy.set_authorization(Credentials::basic("John Doe", "Agent1234").unwrap());
//! proxy.set_authorization(Authorization::basic("John Doe", "Agent1234"));
//! let connector = HttpConnector::new();
//! # #[cfg(not(any(feature = "tls", feature = "rustls-base")))]
//! # let proxy_connector = ProxyConnector::from_proxy_unsecured(connector, proxy);
Expand Down Expand Up @@ -77,7 +77,7 @@ use native_tls::TlsConnector as NativeTlsConnector;
use tokio_native_tls::TlsConnector;
#[cfg(feature = "rustls-base")]
use tokio_rustls::TlsConnector;
use typed_headers::{Authorization, Credentials, HeaderMapExt, ProxyAuthorization};
use headers::{Authorization, authorization::Credentials, HeaderMapExt, ProxyAuthorization};
#[cfg(feature = "rustls-base")]
use webpki::DNSNameRef;

Expand Down Expand Up @@ -187,18 +187,18 @@ impl Proxy {
}

/// Set `Proxy` authorization
pub fn set_authorization(&mut self, credentials: Credentials) {
pub fn set_authorization<C: Credentials + Clone>(&mut self, credentials: Authorization::<C>) {
match self.intercept {
Intercept::Http => {
self.headers.typed_insert(&Authorization(credentials));
self.headers.typed_insert(Authorization(credentials.0));
}
Intercept::Https => {
self.headers.typed_insert(&ProxyAuthorization(credentials));
self.headers.typed_insert(ProxyAuthorization(credentials.0));
}
_ => {
self.headers
.typed_insert(&Authorization(credentials.clone()));
self.headers.typed_insert(&ProxyAuthorization(credentials));
.typed_insert(Authorization(credentials.0.clone()));
self.headers.typed_insert(ProxyAuthorization(credentials.0));
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/tunnel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ mod tests {
fn test_tunnel() {
let addr = mock_tunnel!();

let mut core = Runtime::new().unwrap();
let core = Runtime::new().unwrap();
let work = TcpStream::connect(&addr);
let host = addr.ip().to_string();
let port = addr.port();
Expand All @@ -193,7 +193,7 @@ mod tests {
fn test_tunnel_eof() {
let addr = mock_tunnel!(b"HTTP/1.1 200 OK");

let mut core = Runtime::new().unwrap();
let core = Runtime::new().unwrap();
let work = TcpStream::connect(&addr);
let host = addr.ip().to_string();
let port = addr.port();
Expand All @@ -206,7 +206,7 @@ mod tests {
fn test_tunnel_bad_response() {
let addr = mock_tunnel!(b"foo bar baz hallo");

let mut core = Runtime::new().unwrap();
let core = Runtime::new().unwrap();
let work = TcpStream::connect(&addr);
let host = addr.ip().to_string();
let port = addr.port();
Expand Down

0 comments on commit 5b9abef

Please sign in to comment.