Skip to content

Commit

Permalink
Add network proxy support to upload command
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed May 26, 2022
1 parent 21ba501 commit ff4edc4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ clap_complete_fig = "3.1.0"
configparser = { version = "3.0.0", optional = true }
multipart = { version = "0.18.0", features = ["client"], default-features = false, optional = true }
rpassword = { version = "6.0.1", optional = true }
ureq = { version = "2.3.1", features = ["gzip"], default-features = false, optional = true }
ureq = { version = "2.3.1", features = ["gzip", "socks-proxy"], default-features = false, optional = true }
native-tls-crate = { package = "native-tls", version = "0.2.8", optional = true }
tracing = "0.1.34"

Expand Down
24 changes: 20 additions & 4 deletions src/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,31 @@ pub fn upload(registry: &Registry, wheel_path: &Path) -> Result<(), UploadError>

let encoded = base64::encode(&format!("{}:{}", registry.username, registry.password));

let http_proxy = env::var("HTTPS_PROXY")
.or_else(|_| env::var("https_proxy"))
.or_else(|_| env::var("HTTP_PROXY"))
.or_else(|_| env::var("http_proxy"));

#[cfg(not(feature = "native-tls"))]
let agent = ureq::agent();
let agent = {
let mut builder = ureq::builder();
if let Ok(proxy) = http_proxy {
let proxy = ureq::Proxy::new(proxy)?;
builder = builder.proxy(proxy);
};
builder.build()
};

#[cfg(feature = "native-tls")]
let agent = {
use std::sync::Arc;
ureq::builder()
.tls_connector(Arc::new(native_tls_crate::TlsConnector::new()?))
.build()
let mut builder =
ureq::builder().tls_connector(Arc::new(native_tls_crate::TlsConnector::new()?));
if let Ok(proxy) = http_proxy {
let proxy = ureq::Proxy::new(proxy)?;
builder = builder.proxy(proxy);
};
builder.build()
};

let response = agent
Expand Down

0 comments on commit ff4edc4

Please sign in to comment.