Skip to content

Commit

Permalink
Make proxy available without the feature
Browse files Browse the repository at this point in the history
When we introduced the `rustls` feature, we did it like this:

```toml
[features]
proxy = ["hyper-proxy"]
rustls = ["hyper-proxy/rustls", "tokio-rustls", "hyper-rustls"]
tls = ["hyper-proxy/tls", "native-tls", "tokio-tls", "hyper-tls"]
```

A problem is hidden here: enabling an optional dependency's feature
enabled the dependency. Because of this, `hyper-proxy` is already being
downloaded and compiled, even if `proxy` isn't enabled:

```
$ cargo c
             …
    Checking hyper-proxy v0.6.0
    Checking tbot v0.5.1 (…)
```

But to be able to use it, you have to enable the `proxy` feature, which seems
odd. Since cargo doesn't provide a way to enable an optional dependency's
feature without enabling the dependency (at least yet; rust-lang/cargo#3494),
I think that it's better to always provide proxy functionality.
  • Loading branch information
snejugal committed Mar 30, 2020
1 parent e1377c7 commit e298c5c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ categories = [

[dependencies]
hyper = { version = "0.13.3", default-features = false }
hyper-proxy = { version = "0.6", optional = true, default-features = false }
hyper-proxy = { version = "0.6", default-features = false }
tokio = { version = "0.2", features = ["time", "rt-core", "tcp"] }
serde_json = "1"
serde = { version = "1.0.34", features = ["derive"] }
Expand All @@ -41,7 +41,7 @@ tracing-futures = "0.2"
meval = "0.2"

[features]
proxy = ["hyper-proxy"]
proxy = []
rustls = ["hyper-proxy/rustls", "tokio-rustls", "hyper-rustls"]
tls = ["hyper-proxy/tls", "native-tls", "tokio-tls", "hyper-tls"]
default = ["tls"]
Expand Down Expand Up @@ -80,7 +80,7 @@ required-features = ["tokio/macros"]

[[example]]
name = "proxy"
required-features = ["tokio/macros", "proxy"]
required-features = ["tokio/macros"]

[[example]]
name = "sticker_packs"
Expand Down
4 changes: 0 additions & 4 deletions src/connectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@ use hyper_rustls::HttpsConnector;
#[cfg(feature = "tls")]
use hyper_tls::HttpsConnector;

#[cfg(feature = "proxy")]
pub use hyper_proxy as proxy;
#[cfg(feature = "proxy")]
use proxy::ProxyConnector;

/// The default HTTPS connector.
pub type Https = HttpsConnector<HttpConnector>;

#[cfg(feature = "proxy")]
/// The default proxy connector.
pub type Proxy = ProxyConnector<Https>;

Expand All @@ -29,7 +26,6 @@ pub fn https() -> Https {
HttpsConnector::new()
}

#[cfg(feature = "proxy")]
/// Constructs a proxy connector.
pub fn proxy(proxy: proxy::Proxy) -> Proxy {
ProxyConnector::from_proxy(https(), proxy).unwrap_or_else(|error| {
Expand Down

0 comments on commit e298c5c

Please sign in to comment.