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

Support native TLS #31

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 132 additions & 0 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ readme = "./README.md"
edition = "2018"

[dependencies]
anyhow = "1.0"
ureq = "2.6"
anyhow = "1.0"
ureq = { version = "2.6", features = ["native-tls"] }
dirs-next = "2.0.0"
flate2 = "1.0"
fs4 = "0.6.6"
Expand All @@ -20,6 +20,7 @@ is_executable = "0.1"
siphasher = "0.3"
tar = "0.4"
zip_next = "1.0"
native-tls = "0.2.12"

[dev-dependencies]
tempfile = "3.1"
15 changes: 14 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use std::fs::File;
use std::hash::{Hash, Hasher};
use std::io;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use ureq::Response;

/// Global cache for wasm-pack, currently containing binaries downloaded from
/// urls like wasm-bindgen and such.
Expand Down Expand Up @@ -389,7 +391,18 @@ impl Download {
}

fn download_binary(url: &str) -> Result<Vec<u8>> {
let response = ureq::get(url).call()?;
let use_native_tls = env::var("USE_NATIVE_TLS").ok();
let response: Response;

if use_native_tls.as_deref() == Some("1") {
response = ureq::AgentBuilder::new()
.tls_connector(Arc::new(native_tls::TlsConnector::new()?))
.build()
.get(url)
.call()?;
} else {
response = ureq::get(url).call()?;
}

let status_code = response.status();

Expand Down