Repository: tauri-apps/tauri
File: crates/tauri-bundler/src/bundle/windows/util.rs (Rust)

Code before:
  if !file_path.exists() {
    std::fs::write(&file_path, download(WEBVIEW2_BOOTSTRAPPER_URL)?)?;
  }
  Ok(file_path)
}

pub fn download_webview2_offline_installer(base_path: &Path, arch: &str) -> crate::Result<PathBuf> {
  let url = if arch == "x64" {
    WEBVIEW2_OFFLINE_INSTALLER_X64_URL
  } else {
    WEBVIEW2_OFFLINE_INSTALLER_X86_URL
  };
  let (guid, filename) = webview2_guid_path(url)?;
  let dir_path = base_path.join(guid);
  let file_path = dir_path.join(filename);
  if !file_path.exists() {
    create_dir_all(dir_path)?;
    std::fs::write(&file_path, download(url)?)?;
  }
  Ok(file_path)
}

pub fn download(url: &str) -> crate::Result<Vec<u8>> {
  log::info!(action = "Downloading"; "{}", url);

  let (agent, url) = match std::env::var("GITHUB_CDN") {
    Ok(cdn) => {
      let mut parsed_cdn = url::Url::parse(&cdn).expect("Invalid cdn");
      parsed_cdn.set_path(url);

      (ureq::AgentBuilder::new().build(), parsed_cdn.to_string())
    }
    Err(_) => (
      ureq::AgentBuilder::new().try_proxy_from_env(true).build(),
      url.to_owned(),
    ),
  };

  let response = agent.get(&url).call().map_err(Box::new)?;
  let mut bytes = Vec::new();
  response.into_reader().read_to_end(&mut bytes)?;
  Ok(bytes)
}

#[derive(Clone, Copy)]
pub enum HashAlgorithm {
  #[cfg(target_os = "windows")]
  Sha256,
  Sha1,
}


Review comment (suggestion):
I think `GITHUB_CDN` is a bit vague, maybe `TAURI_BUNDLER_TOOLS_DOWNLOAD_HOST` is better here. You also need to document that env var in `crates/tauri-cli/ENVIRONEMENT_VARIABLES.md` file

Code after:
pub fn download_webview2_bootstrapper(base_path: &Path) -> crate::Result<PathBuf> {
  let file_path = base_path.join("MicrosoftEdgeWebview2Setup.exe");
  if !file_path.exists() {
    std::fs::write(&file_path, download(WEBVIEW2_BOOTSTRAPPER_URL)?)?;
  }
  Ok(file_path)
}

pub fn download_webview2_offline_installer(base_path: &Path, arch: &str) -> crate::Result<PathBuf> {
  let url = if arch == "x64" {
    WEBVIEW2_OFFLINE_INSTALLER_X64_URL
  } else {
    WEBVIEW2_OFFLINE_INSTALLER_X86_URL
  };
  let (guid, filename) = webview2_guid_path(url)?;
  let dir_path = base_path.join(guid);
  let file_path = dir_path.join(filename);
  if !file_path.exists() {
    create_dir_all(dir_path)?;
    std::fs::write(&file_path, download(url)?)?;
  }
  Ok(file_path)
}

fn create_agent_and_url(url: &str) -> crate::Result<(ureq::Agent, String)> {
  match std::env::var("TAURI_BUNDLER_TOOLS_GITHUB_MIRROR") {
    Ok(cdn) if url.starts_with("https://github.com/") => {
      let mut parsed_cdn = Url::parse(&cdn)?;
      parsed_cdn.set_path(url);
      Ok((AgentBuilder::new().build(), parsed_cdn.into()))
    }
    _ => Ok((
      AgentBuilder::new().try_proxy_from_env(true).build(),
      url.to_owned(),
    )),
  }
}

pub fn download(url: &str) -> crate::Result<Vec<u8>> {
  log::info!(action = "Downloading"; "{}", url);

  let (agent, final_url) = create_agent_and_url(url)?;

  let response = agent.get(&final_url).call().map_err(Box::new)?;
  let mut bytes = Vec::new();
  response.into_reader().read_to_end(&mut bytes)?;
  Ok(bytes)
}

#[derive(Clone, Copy)]
pub enum HashAlgorithm {