Skip to content

Commit a061b23

Browse files
committed
Take advantage of weak features in Rust 1.60 for TLS enablement
Previously it was impossible to have a unified feature named `rustls` or `native-tls` that would turn on the respective TLS backend in the chosen transport (`reqwest` or `ureq`) as a feature of `<crate>/tls` would implicitly turn on `<crate>`. Since Rust 1.60 it is now possible to specify this crate-feature enablement through the use of the question mark in `<crate>?/tls`, which will only enable the `tls` feature if `<crate>` was enabled through other means (another feature). Secondly we can now also let optional crates have the same name as a feature, and use `dep:<crate>` to refer to the crate instead of the dependency, making for a more pleasant experience without renames to underscore suffixes.
1 parent 62f7b8e commit a061b23

File tree

7 files changed

+22
-26
lines changed

7 files changed

+22
-26
lines changed

sentry/Cargo.toml

+12-12
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ test = ["sentry-core/test"]
3838
debug-logs = ["log_", "sentry-core/debug-logs"]
3939
# transports
4040
transport = ["reqwest", "native-tls"]
41-
reqwest = ["reqwest_", "httpdate", "tokio"]
42-
curl = ["curl_", "httpdate"]
43-
surf-h1 = ["surf_/h1-client", "httpdate"]
44-
surf = ["surf_/curl-client", "httpdate", "tokio"]
45-
native-tls = ["reqwest_/default-tls"]
46-
rustls = ["reqwest_/rustls-tls"]
47-
ureq = ["ureq_/tls", "httpdate"]
48-
ureq-native-tls = ["ureq_/native-tls", "httpdate"]
41+
reqwest = ["dep:reqwest", "httpdate", "tokio"]
42+
curl = ["dep:curl", "httpdate"]
43+
surf-h1 = ["surf/h1-client", "httpdate"]
44+
surf = ["surf/curl-client", "httpdate", "tokio"]
45+
ureq = ["dep:ureq", "httpdate"]
46+
# transport settings
47+
native-tls = ["reqwest?/default-tls", "ureq?/native-tls"]
48+
rustls = ["reqwest?/rustls-tls", "ureq?/tls"]
4949

5050
[dependencies]
5151
sentry-core = { version = "0.25.0", path = "../sentry-core", features = ["client"] }
@@ -59,13 +59,13 @@ sentry-slog = { version = "0.25.0", path = "../sentry-slog", optional = true }
5959
sentry-tower = { version = "0.25.0", path = "../sentry-tower", optional = true }
6060
sentry-tracing = { version = "0.25.0", path = "../sentry-tracing", optional = true }
6161
log_ = { package = "log", version = "0.4.8", optional = true, features = ["std"] }
62-
reqwest_ = { package = "reqwest", version = "0.11", optional = true, features = ["blocking", "json"], default-features = false }
63-
curl_ = { package = "curl", version = "0.4.25", optional = true }
62+
reqwest = { version = "0.11", optional = true, features = ["blocking", "json"], default-features = false }
63+
curl = { version = "0.4.25", optional = true }
6464
httpdate = { version = "1.0.0", optional = true }
65-
surf_ = { package = "surf", version = "2.0.0", optional = true, default-features = false }
65+
surf = { version = "2.0.0", optional = true, default-features = false }
6666
serde_json = { version = "1.0.48", optional = true }
6767
tokio = { version = "1.0", features = ["rt"], optional = true }
68-
ureq_ = { package = "ureq", version = "2.3.0", optional = true, default-features = false }
68+
ureq = { version = "2.3.0", optional = true, default-features = false }
6969

7070
[dev-dependencies]
7171
sentry-anyhow = { path = "../sentry-anyhow" }

sentry/src/transports/curl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::io::{Cursor, Read};
22
use std::time::Duration;
33

4-
use curl_::{self as curl, easy::Easy as CurlClient};
4+
use curl::{self as curl, easy::Easy as CurlClient};
55

66
use super::thread::TransportThread;
77

sentry/src/transports/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ mod tokio_thread;
1616
#[cfg(feature = "reqwest")]
1717
mod reqwest;
1818
#[cfg(feature = "reqwest")]
19-
pub use reqwest::ReqwestHttpTransport;
19+
pub use self::reqwest::ReqwestHttpTransport;
2020

2121
#[cfg(feature = "curl")]
2222
mod curl;
2323
#[cfg(feature = "curl")]
24-
pub use curl::CurlHttpTransport;
24+
pub use self::curl::CurlHttpTransport;
2525

2626
#[cfg(feature = "surf")]
2727
mod surf;
2828
#[cfg(feature = "surf")]
29-
pub use surf::SurfHttpTransport;
29+
pub use self::surf::SurfHttpTransport;
3030

3131
#[cfg(feature = "ureq")]
3232
mod ureq;
3333
#[cfg(feature = "ureq")]
34-
pub use ureq::UreqHttpTransport;
34+
pub use self::ureq::UreqHttpTransport;
3535

3636
#[cfg(feature = "reqwest")]
3737
type DefaultTransport = ReqwestHttpTransport;

sentry/src/transports/reqwest.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::time::Duration;
22

3-
use reqwest_::{header as ReqwestHeaders, Client as ReqwestClient, Proxy, StatusCode};
3+
use reqwest::{header as ReqwestHeaders, Client as ReqwestClient, Proxy, StatusCode};
44

55
use super::tokio_thread::TransportThread;
66

@@ -31,7 +31,7 @@ impl ReqwestHttpTransport {
3131

3232
fn new_internal(options: &ClientOptions, client: Option<ReqwestClient>) -> Self {
3333
let client = client.unwrap_or_else(|| {
34-
let mut builder = reqwest_::Client::builder();
34+
let mut builder = reqwest::Client::builder();
3535
if let Some(url) = options.http_proxy.as_ref() {
3636
builder = builder.proxy(Proxy::http(url.as_ref()).unwrap());
3737
};

sentry/src/transports/surf.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::time::Duration;
22

3-
use surf_::{http::headers as SurfHeaders, Client as SurfClient, StatusCode};
3+
use surf::{http::headers as SurfHeaders, Client as SurfClient, StatusCode};
44

55
use super::tokio_thread::TransportThread;
66

sentry/src/transports/ureq.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use std::time::Duration;
22

3-
#[cfg(fdoc)]
4-
use ureq_ as ureq;
5-
use ureq_::{Agent, AgentBuilder, Proxy};
3+
use ureq::{Agent, AgentBuilder, Proxy};
64

75
use super::thread::TransportThread;
86

@@ -11,8 +9,6 @@ use crate::{sentry_debug, types::Scheme, ClientOptions, Envelope, Transport};
119
/// A [`Transport`] that sends events via the [`ureq`] library.
1210
///
1311
/// This is enabled by the `ureq` feature flag.
14-
///
15-
/// [`ureq`]: https://crates.io/crates/ureq
1612
#[cfg_attr(doc_cfg, doc(cfg(feature = "ureq")))]
1713
pub struct UreqHttpTransport {
1814
thread: TransportThread,

sentry/tests/test_tower.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use sentry::{
88
ClientOptions, Hub,
99
};
1010
use sentry_tower::SentryLayer;
11-
use tower_::{ServiceBuilder, ServiceExt};
11+
use tower::{ServiceBuilder, ServiceExt};
1212

1313
#[test]
1414
fn test_tower_hub() {

0 commit comments

Comments
 (0)