Skip to content

Commit

Permalink
fix: Do not panic on invalid Proxy (#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
Swatinem committed Apr 26, 2022
1 parent 799f211 commit 7e6df65
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 10 deletions.
8 changes: 6 additions & 2 deletions sentry/src/transports/curl.rs
Expand Up @@ -44,10 +44,14 @@ impl CurlHttpTransport {

match (scheme, &http_proxy, &https_proxy) {
(Scheme::Https, _, &Some(ref proxy)) => {
handle.proxy(proxy).unwrap();
if let Err(err) = handle.proxy(proxy) {
sentry_debug!("invalid proxy: {:?}", err);
}
}
(_, &Some(ref proxy), _) => {
handle.proxy(proxy).unwrap();
if let Err(err) = handle.proxy(proxy) {
sentry_debug!("invalid proxy: {:?}", err);
}
}
_ => {}
}
Expand Down
18 changes: 16 additions & 2 deletions sentry/src/transports/reqwest.rs
Expand Up @@ -33,10 +33,24 @@ impl ReqwestHttpTransport {
let client = client.unwrap_or_else(|| {
let mut builder = reqwest_::Client::builder();
if let Some(url) = options.http_proxy.as_ref() {
builder = builder.proxy(Proxy::http(url.as_ref()).unwrap());
match Proxy::http(url.as_ref()) {
Ok(proxy) => {
builder = builder.proxy(proxy);
}
Err(err) => {
sentry_debug!("invalid proxy: {:?}", err);
}
}
};
if let Some(url) = options.https_proxy.as_ref() {
builder = builder.proxy(Proxy::https(url.as_ref()).unwrap());
match Proxy::https(url.as_ref()) {
Ok(proxy) => {
builder = builder.proxy(proxy);
}
Err(err) => {
sentry_debug!("invalid proxy: {:?}", err);
}
}
};
builder.build().unwrap()
});
Expand Down
22 changes: 16 additions & 6 deletions sentry/src/transports/ureq.rs
Expand Up @@ -34,12 +34,22 @@ impl UreqHttpTransport {
let mut builder = AgentBuilder::new();

match (scheme, &options.http_proxy, &options.https_proxy) {
(Scheme::Https, _, &Some(ref proxy)) => {
builder = builder.proxy(Proxy::new(proxy).unwrap());
}
(_, &Some(ref proxy), _) => {
builder = builder.proxy(Proxy::new(proxy).unwrap());
}
(Scheme::Https, _, &Some(ref proxy)) => match Proxy::new(proxy) {
Ok(proxy) => {
builder = builder.proxy(proxy);
}
Err(err) => {
sentry_debug!("invalid proxy: {:?}", err);
}
},
(_, &Some(ref proxy), _) => match Proxy::new(proxy) {
Ok(proxy) => {
builder = builder.proxy(proxy);
}
Err(err) => {
sentry_debug!("invalid proxy: {:?}", err);
}
},
_ => {}
}

Expand Down
8 changes: 8 additions & 0 deletions sentry/tests/test_client.rs
Expand Up @@ -71,3 +71,11 @@ fn test_concurrent_init() {
.join()
.unwrap();
}

#[test]
fn test_invalid_proxy() {
let _guard = sentry::init(sentry::ClientOptions {
https_proxy: Some("".into()),
..Default::default()
});
}

0 comments on commit 7e6df65

Please sign in to comment.