Skip to content

Commit

Permalink
Upgrade HTTP URLs to HTTPS
Browse files Browse the repository at this point in the history
Resolves #356
  • Loading branch information
russellbanks committed Feb 22, 2024
1 parent 62ec874 commit 824a52d
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 42 deletions.
60 changes: 30 additions & 30 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions src/commands/new_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ use crate::types::urls::license_url::LicenseUrl;
use crate::types::urls::package_url::PackageUrl;
use crate::types::urls::publisher_url::PublisherUrl;
use crate::types::urls::release_notes_url::ReleaseNotesUrl;
use crate::types::urls::url::Url;
use crate::update_state::UpdateState;
use base64ct::Encoding;
use camino::Utf8PathBuf;
Expand All @@ -63,6 +62,7 @@ use std::num::{NonZeroU32, NonZeroU8};
use std::ops::Not;
use std::time::Duration;
use strum::IntoEnumIterator;
use url::Url;

#[derive(Parser)]
pub struct NewVersion {
Expand Down Expand Up @@ -250,7 +250,7 @@ impl NewVersion {
.as_mut()
.and_then(|zip| mem::take(&mut zip.nested_installer_files)),
scope: Scope::find_from_url(url.as_str()),
installer_url: url.clone(),
installer_url: url.clone().into(),
installer_sha_256: mem::take(&mut analyser.installer_sha_256),
signature_sha_256: mem::take(&mut analyser.signature_sha_256),
installer_switches: installer_switches
Expand Down
4 changes: 2 additions & 2 deletions src/commands/update_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use crate::types::installer_type::InstallerType;
use crate::types::manifest_version::ManifestVersion;
use crate::types::package_identifier::PackageIdentifier;
use crate::types::package_version::PackageVersion;
use crate::types::urls::url::Url;
use crate::update_state::UpdateState;
use base64ct::Encoding;
use camino::Utf8PathBuf;
Expand All @@ -35,6 +34,7 @@ use std::mem;
use std::num::{NonZeroU32, NonZeroU8};
use std::ops::Not;
use std::time::Duration;
use url::Url;

#[derive(Parser)]
pub struct UpdateVersion {
Expand Down Expand Up @@ -138,7 +138,7 @@ impl UpdateVersion {
architecture: download.architecture.unwrap(),
installer_type: Some(download.installer_type),
scope: Scope::find_from_url(url.as_str()),
installer_url: url.clone(),
installer_url: url.clone().into(),
..Installer::default()
})
.collect::<Vec<_>>();
Expand Down
25 changes: 17 additions & 8 deletions src/download_file.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::file_analyser::FileAnalyser;
use crate::types::urls::url::Url;
use crate::url_utils::find_architecture;
use camino::Utf8Path;
use chrono::{DateTime, NaiveDate};
Expand All @@ -9,7 +8,7 @@ use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
use itertools::Itertools;
use memmap2::Mmap;
use reqwest::header::{HeaderValue, CONTENT_DISPOSITION, LAST_MODIFIED};
use reqwest::Client;
use reqwest::{Client, Response};
use sha2::{Digest, Sha256};
use std::borrow::Cow;
use std::cmp::min;
Expand All @@ -18,13 +17,27 @@ use std::fs::File;
use std::future::Future;
use std::io::Cursor;
use tokio::io::AsyncWriteExt;
use url::Url;
use uuid::Uuid;

async fn download_file(
client: &Client,
url: Url,
mut url: Url,
multi_progress: &MultiProgress,
) -> Result<DownloadedFile> {
if url.scheme() == "http" {
url.set_scheme("https").unwrap();
if client
.head(url.as_str())
.send()
.await
.and_then(Response::error_for_status)
.is_err()
{
url.set_scheme("http").unwrap();
}
}

let res = client
.get(url.as_str())
.send()
Expand Down Expand Up @@ -79,11 +92,7 @@ async fn download_file(
})
}

fn get_file_name(
url: &Url,
final_url: &url::Url,
content_disposition: Option<&HeaderValue>,
) -> String {
fn get_file_name(url: &Url, final_url: &Url, content_disposition: Option<&HeaderValue>) -> String {
if let Some(content_disposition) = content_disposition.and_then(|value| value.to_str().ok()) {
let mut sections = content_disposition.split(';');
let _disposition = sections.next();
Expand Down
6 changes: 6 additions & 0 deletions src/types/urls/url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ use percent_encoding::percent_decode_str;
derive(Clone, Deref, FromStr, Display, Default, Deserialize, Serialize, Hash, Eq, PartialEq, Ord, PartialOrd, Debug)
)]
pub struct Url(url::Url);

impl From<url::Url> for Url {
fn from(value: url::Url) -> Self {
Self::new(value)
}
}

0 comments on commit 824a52d

Please sign in to comment.