Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Do not panic on invalid Proxy #450

Merged
merged 2 commits into from Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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()
});
}