diff --git a/src/curl.cpp b/src/curl.cpp index 579af5e..fca5113 100644 --- a/src/curl.cpp +++ b/src/curl.cpp @@ -363,6 +363,7 @@ curltime_t S3fsCurl::curl_times; curlprogress_t S3fsCurl::curl_progress; string S3fsCurl::curl_ca_bundle; mimes_t S3fsCurl::mimeTypes; +string S3fsCurl::userAgent; int S3fsCurl::max_parallel_cnt = 5; // default off_t S3fsCurl::multipart_size = MULTIPART_SIZE; // default bool S3fsCurl::is_sigv4 = true; // default @@ -614,6 +615,19 @@ bool S3fsCurl::InitMimeType(const char* MimeFile) return true; } +void S3fsCurl::InitUserAgent(void) +{ + if(S3fsCurl::userAgent.empty()){ + S3fsCurl::userAgent = "s3fs/"; + S3fsCurl::userAgent += VERSION; + S3fsCurl::userAgent += " (commit hash "; + S3fsCurl::userAgent += COMMIT_HASH_VAL; + S3fsCurl::userAgent += "; "; + S3fsCurl::userAgent += s3fs_crypt_lib_name(); + S3fsCurl::userAgent += ")"; + } +} + // // @param s e.g., "index.html" // @return e.g., "text/html" @@ -1480,20 +1494,7 @@ bool S3fsCurl::AddUserAgent(CURL* hCurl) return false; } if(S3fsCurl::IsUserAgentFlag()){ - static string strua; - static bool init = false; - - if(!init){ - strua = "s3fs/"; - strua += VERSION; - strua += " (commit hash "; - strua += COMMIT_HASH_VAL; - strua += "; "; - strua += s3fs_crypt_lib_name(); - strua += ")"; - init = true; - } - curl_easy_setopt(hCurl, CURLOPT_USERAGENT, strua.c_str()); + curl_easy_setopt(hCurl, CURLOPT_USERAGENT, S3fsCurl::userAgent.c_str()); } return true; } diff --git a/src/curl.h b/src/curl.h index c75b4dd..be9feb5 100644 --- a/src/curl.h +++ b/src/curl.h @@ -236,6 +236,7 @@ class S3fsCurl static curlprogress_t curl_progress; static std::string curl_ca_bundle; static mimes_t mimeTypes; + static std::string userAgent; static int max_parallel_cnt; static off_t multipart_size; static bool is_sigv4; @@ -377,6 +378,7 @@ class S3fsCurl static bool IsSignatureV4(void) { return S3fsCurl::is_sigv4; } static bool SetUserAgentFlag(bool isset) { bool bresult = S3fsCurl::is_ua; S3fsCurl::is_ua = isset; return bresult; } static bool IsUserAgentFlag(void) { return S3fsCurl::is_ua; } + static void InitUserAgent(void); // methods bool CreateCurlHandle(bool force = false); diff --git a/src/s3fs.cpp b/src/s3fs.cpp index 8df9aa2..7f159b8 100644 --- a/src/s3fs.cpp +++ b/src/s3fs.cpp @@ -4935,6 +4935,9 @@ int main(int argc, char* argv[]) exit(EXIT_FAILURE); } + // set user agent + S3fsCurl::InitUserAgent(); + // There's room for more command line error checking // Check to see if the bucket name contains periods and https (SSL) is