From 2bdae98c7e471a317695956095ed33681ae93509 Mon Sep 17 00:00:00 2001 From: Simon Quigley Date: Sun, 26 Jan 2025 16:46:21 -0600 Subject: [PATCH] Try to also recognize NO_PROXY --- cpp/ci_logic.cpp | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/cpp/ci_logic.cpp b/cpp/ci_logic.cpp index 3f17446..70e8991 100644 --- a/cpp/ci_logic.cpp +++ b/cpp/ci_logic.cpp @@ -424,11 +424,29 @@ void CiLogic::clone_or_fetch(const std::filesystem::path &repo_dir, ensure_git_inited(); // Use proxy settings via env var if they exist - const char* proxy = repo_url.rfind("https", 0) == 0 ? std::getenv("HTTPS_PROXY") : std::getenv("HTTP_PROXY"); + bool proxy = false; git_proxy_options proxy_opts = GIT_PROXY_OPTIONS_INIT; - if (proxy) { - proxy_opts.type = GIT_PROXY_SPECIFIED; - proxy_opts.url = proxy; + { + const char* tmp_proxy = repo_url.rfind("https", 0) == 0 ? std::getenv("HTTPS_PROXY") : std::getenv("HTTP_PROXY"); + if (tmp_proxy) { + const char* no_proxy_env = std::getenv("NO_PROXY"); + if (no_proxy_env) { + std::istringstream iss(std::string{no_proxy_env}); + std::string entry; + bool found_no_proxy = false; + while (std::getline(iss, entry, ',')) { + if (!entry.empty() && repo_url.contains(entry)) { + found_no_proxy = true; + break; + } + } + proxy = !found_no_proxy; + } else { + proxy = true; + proxy_opts.type = GIT_PROXY_SPECIFIED; + proxy_opts.url = tmp_proxy; + } + } } git_repository* repo = nullptr;