From 11153a5275faf824419150070b6d2e2a629a0631 Mon Sep 17 00:00:00 2001 From: bytedream Date: Wed, 4 May 2022 17:35:35 +0200 Subject: [PATCH] Expand usage of https only mode to github & fix typo --- src/main.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0b72aa4..3402631 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,6 +18,7 @@ lazy_static! { static ref ENABLE_REGEX: bool = env_lookup("ENABLE_REGEX", false); static ref MAX_PATTERN_LEN: i32 = env_lookup("MAX_PATTER_LEN", 70); + static ref HTTPS_ONLY: bool = env_lookup("HTTPS_ONLY", true); static ref ENABLE_CUSTOM_HOSTS: bool = env_lookup("ENABLE_CUSTOM_HOSTS", false); static ref TAG_PATTERN: Regex = Regex::new(r"(?P\d+)([.-_](?P\d+)([.-_](?P\d+))?([.-_]?(?P
[\w\d]+))?)?").unwrap();
@@ -98,7 +99,7 @@ async fn request_github(user: &str, repo: &str, pattern: &str, query: web::Query
     }
 
     let mut res = client()
-        .get(format!("https://api.github.com/repos/{}/{}/releases/latest", user, repo))
+        .get(format!("{}://api.github.com/repos/{}/{}/releases/latest", if *HTTPS_ONLY { "https" } else { "http" }, user, repo))
         .header("Accept", "application/vnd.github.v3+json")
         .header("User-Agent", USER_AGENT.as_str())
         .send()
@@ -114,7 +115,7 @@ async fn request_gitea(host: &str, user: &str, repo: &str, pattern: &str, query:
     }
 
     let mut res = client()
-        .get(format!("{}://{}/api/v1/repos/{}/{}/releases?limit=1", if env_lookup("HTTPS_ONLY", true) { "HTTPS" } else { "HTTP" }, host, user, repo))
+        .get(format!("{}://{}/api/v1/repos/{}/{}/releases?limit=1", if *HTTPS_ONLY { "https" } else { "http" }, host, user, repo))
         .header(http::header::CONTENT_TYPE, "application/json")
         .header(http::header::USER_AGENT, USER_AGENT.as_str())
         .send()