From ffc1c995060d0df7fc0d34ea0f3cd41c477c1359 Mon Sep 17 00:00:00 2001 From: timostrunk Date: Wed, 3 May 2023 13:09:11 +0200 Subject: [PATCH] Forward NETRC environment variable to curl, if exported (#2497) Co-authored-by: Timo Strunk --- libmamba/src/core/curl.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/libmamba/src/core/curl.cpp b/libmamba/src/core/curl.cpp index 1f603f4bee..17e706783f 100644 --- a/libmamba/src/core/curl.cpp +++ b/libmamba/src/core/curl.cpp @@ -7,8 +7,9 @@ // TODO remove all these includes later? #include -#include "mamba/core/mamba_fs.hpp" // for fs::exists -#include "mamba/core/util.hpp" // for hide_secrets +#include "mamba/core/environment.hpp" // for NETRC env var +#include "mamba/core/mamba_fs.hpp" // for fs::exists +#include "mamba/core/util.hpp" // for hide_secrets #include "curl.hpp" @@ -30,6 +31,13 @@ namespace mamba curl_easy_setopt(handle, CURLOPT_NETRC, CURL_NETRC_OPTIONAL); curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1L); + // if NETRC is exported in ENV, we forward it to curl + std::string netrc_file = env::get("NETRC").value_or(""); + if (netrc_file != "") + { + curl_easy_setopt(handle, CURLOPT_NETRC_FILE, netrc_file.c_str()); + } + // This can improve throughput significantly, see // https://github.com/curl/curl/issues/9601 curl_easy_setopt(handle, CURLOPT_BUFFERSIZE, 100 * 1024);