From 36e9a3fce704582626bbc9e49a8486acab37200f Mon Sep 17 00:00:00 2001 From: j842 Date: Sun, 17 Aug 2025 22:16:25 +1200 Subject: [PATCH] Update source/src/utils/utils.cpp --- source/src/utils/utils.cpp | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/source/src/utils/utils.cpp b/source/src/utils/utils.cpp index fdbc730..45cd615 100644 --- a/source/src/utils/utils.cpp +++ b/source/src/utils/utils.cpp @@ -2,10 +2,11 @@ #include "httplib.hpp" #include - +#include #include #include #include +#include #include #include #include @@ -479,12 +480,24 @@ HttpResult make_http_request(const std::string& url) { return {false, 0, "", "Invalid URL format"}; } - // Create HTTP client - httplib::Client cli(host); - cli.set_connection_timeout(10); // 10 second timeout + // Create HTTP or HTTPS client based on protocol + std::string protocol = url.substr(0, protocol_end); + std::unique_ptr cli; + + if (protocol == "https") { + // For HTTPS, include the full scheme and host + cli = std::make_unique("https://" + host); + } else if (protocol == "http") { + cli = std::make_unique("http://" + host); + } else { + return {false, 0, "", "Unsupported protocol: " + protocol}; + } + + cli->set_connection_timeout(10); // 10 second timeout + cli->set_read_timeout(30); // 30 second read timeout // Make GET request - auto res = cli.Get(path); + auto res = cli->Get(path); if (!res) { return {false, 0, "", "Failed to connect to server"}; } @@ -499,6 +512,20 @@ HttpResult make_http_request(const std::string& url) { } bool download_file(const std::string &url, const std::string &destination) { + // For HTTPS URLs, use curl as it handles SSL properly in static builds + if (url.substr(0, 8) == "https://") { + std::string cmd = "curl -fsSL " + quote(url) + " -o " + quote(destination) + " 2>/dev/null"; + int result = system(cmd.c_str()); + if (result != 0) { + warning << "Failed to download file from URL: " << url << std::endl; + return false; + } + // Check if file was actually created + std::ifstream check_file(destination); + return check_file.good(); + } + + // For HTTP URLs, use the built-in httplib auto result = make_http_request(url); if (!result.success) { warning << "Failed to download file from URL: " << url << std::endl;