diff --git a/doc/man/s3fs.1 b/doc/man/s3fs.1 index 6c005ec..80eb937 100644 --- a/doc/man/s3fs.1 +++ b/doc/man/s3fs.1 @@ -216,6 +216,10 @@ If this option is specified with nocopapi, the s3fs ignores it. \fB\-o\fR use_path_request_style (use legacy API calling style) Enble compatibility with S3-like APIs which do not support the virtual-host request style, by using the older path request style. .TP +\fB\-o\fR noua (suppress User-Agent header) +Usually s3fs outputs of the User-Agent in "s3fs/ (commit hash ; )" format. +If this option is specified, s3fs suppresses the output of the User-Agent. +.TP \fB\-o\fR dbglevel (default="crit") Set the debug message level. set value as crit(critical), err(error), warn(warning), info(information) to debug level. default debug level is critical. If s3fs run with "-d" option, the debug level is set information. diff --git a/src/curl.cpp b/src/curl.cpp index 2abb81d..7e6304e 100644 --- a/src/curl.cpp +++ b/src/curl.cpp @@ -271,6 +271,7 @@ mimes_t S3fsCurl::mimeTypes; int S3fsCurl::max_parallel_cnt = 5; // default off_t S3fsCurl::multipart_size = MULTIPART_SIZE; // default bool S3fsCurl::is_sigv4 = true; // default +bool S3fsCurl::is_ua = true; // default //------------------------------------------------------------------- // Class methods for S3fsCurl @@ -1344,6 +1345,30 @@ bool S3fsCurl::CheckIAMCredentialUpdate(void) return true; } +bool S3fsCurl::AddUserAgent(CURL* hCurl) +{ + if(!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()); + } + return true; +} + int S3fsCurl::CurlDebugFunc(CURL* hcurl, curl_infotype type, char* data, size_t size, void* userptr) { if(!hcurl){ @@ -1722,6 +1747,8 @@ bool S3fsCurl::RemakeHandle(void) S3FS_PRN_ERR("request type is unknown(%d)", type); return false; } + S3fsCurl::AddUserAgent(hCurl); // put User-Agent + return true; } @@ -2133,6 +2160,7 @@ int S3fsCurl::DeleteRequest(const char* tpath) curl_easy_setopt(hCurl, CURLOPT_URL, url.c_str()); curl_easy_setopt(hCurl, CURLOPT_CUSTOMREQUEST, "DELETE"); curl_easy_setopt(hCurl, CURLOPT_HTTPHEADER, requestHeaders); + S3fsCurl::AddUserAgent(hCurl); // put User-Agent type = REQTYPE_DELETE; @@ -2167,6 +2195,7 @@ int S3fsCurl::GetIAMCredentials(void) curl_easy_setopt(hCurl, CURLOPT_URL, url.c_str()); curl_easy_setopt(hCurl, CURLOPT_WRITEDATA, (void*)bodydata); curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); + S3fsCurl::AddUserAgent(hCurl); // put User-Agent int result = RequestPerform(); @@ -2275,6 +2304,7 @@ bool S3fsCurl::PreHeadRequest(const char* tpath, const char* bpath, const char* // responseHeaders curl_easy_setopt(hCurl, CURLOPT_HEADERDATA, (void*)&responseHeaders); curl_easy_setopt(hCurl, CURLOPT_HEADERFUNCTION, HeaderCallback); + S3fsCurl::AddUserAgent(hCurl); // put User-Agent type = REQTYPE_HEAD; @@ -2421,6 +2451,7 @@ int S3fsCurl::PutHeadRequest(const char* tpath, headers_t& meta, bool is_copy) curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); curl_easy_setopt(hCurl, CURLOPT_INFILESIZE, 0); // Content-Length curl_easy_setopt(hCurl, CURLOPT_HTTPHEADER, requestHeaders); + S3fsCurl::AddUserAgent(hCurl); // put User-Agent type = REQTYPE_PUTHEAD; @@ -2544,6 +2575,7 @@ int S3fsCurl::PutRequest(const char* tpath, headers_t& meta, int fd) }else{ curl_easy_setopt(hCurl, CURLOPT_INFILESIZE, 0); // Content-Length: 0 } + S3fsCurl::AddUserAgent(hCurl); // put User-Agent type = REQTYPE_PUT; @@ -2609,6 +2641,7 @@ int S3fsCurl::PreGetObjectRequest(const char* tpath, int fd, off_t start, ssize_ curl_easy_setopt(hCurl, CURLOPT_HTTPHEADER, requestHeaders); curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, S3fsCurl::DownloadWriteCallback); curl_easy_setopt(hCurl, CURLOPT_WRITEDATA, (void*)this); + S3fsCurl::AddUserAgent(hCurl); // put User-Agent // set info for callback func. // (use only fd, startpos and size, other member is not used.) @@ -2689,6 +2722,7 @@ int S3fsCurl::CheckBucket(void) curl_easy_setopt(hCurl, CURLOPT_WRITEDATA, (void*)bodydata); curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); curl_easy_setopt(hCurl, CURLOPT_HTTPHEADER, requestHeaders); + S3fsCurl::AddUserAgent(hCurl); // put User-Agent type = REQTYPE_CHKBUCKET; @@ -2742,6 +2776,7 @@ int S3fsCurl::ListBucketRequest(const char* tpath, const char* query) curl_easy_setopt(hCurl, CURLOPT_WRITEDATA, (void*)bodydata); curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); curl_easy_setopt(hCurl, CURLOPT_HTTPHEADER, requestHeaders); + S3fsCurl::AddUserAgent(hCurl); // put User-Agent type = REQTYPE_LISTBUCKET; @@ -2856,6 +2891,7 @@ int S3fsCurl::PreMultipartPostRequest(const char* tpath, headers_t& meta, string curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); curl_easy_setopt(hCurl, CURLOPT_POSTFIELDSIZE, 0); curl_easy_setopt(hCurl, CURLOPT_HTTPHEADER, requestHeaders); + S3fsCurl::AddUserAgent(hCurl); // put User-Agent type = REQTYPE_PREMULTIPOST; @@ -2968,6 +3004,7 @@ int S3fsCurl::CompleteMultipartPostRequest(const char* tpath, string& upload_id, curl_easy_setopt(hCurl, CURLOPT_POSTFIELDSIZE, static_cast(postdata_remaining)); curl_easy_setopt(hCurl, CURLOPT_READDATA, (void*)this); curl_easy_setopt(hCurl, CURLOPT_READFUNCTION, S3fsCurl::ReadCallback); + S3fsCurl::AddUserAgent(hCurl); // put User-Agent type = REQTYPE_COMPLETEMULTIPOST; @@ -3018,6 +3055,7 @@ int S3fsCurl::MultipartListRequest(string& body) curl_easy_setopt(hCurl, CURLOPT_WRITEDATA, (void*)bodydata); curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); curl_easy_setopt(hCurl, CURLOPT_HTTPHEADER, requestHeaders); + S3fsCurl::AddUserAgent(hCurl); // put User-Agent type = REQTYPE_MULTILIST; @@ -3070,6 +3108,7 @@ int S3fsCurl::AbortMultipartUpload(const char* tpath, string& upload_id) curl_easy_setopt(hCurl, CURLOPT_URL, url.c_str()); curl_easy_setopt(hCurl, CURLOPT_CUSTOMREQUEST, "DELETE"); curl_easy_setopt(hCurl, CURLOPT_HTTPHEADER, requestHeaders); + S3fsCurl::AddUserAgent(hCurl); // put User-Agent type = REQTYPE_ABORTMULTIUPLOAD; @@ -3164,6 +3203,7 @@ int S3fsCurl::UploadMultipartPostSetup(const char* tpath, int part_num, const st curl_easy_setopt(hCurl, CURLOPT_READFUNCTION, S3fsCurl::UploadReadCallback); curl_easy_setopt(hCurl, CURLOPT_READDATA, (void*)this); curl_easy_setopt(hCurl, CURLOPT_HTTPHEADER, requestHeaders); + S3fsCurl::AddUserAgent(hCurl); // put User-Agent type = REQTYPE_UPLOADMULTIPOST; @@ -3262,6 +3302,7 @@ int S3fsCurl::CopyMultipartPostRequest(const char* from, const char* to, int par curl_easy_setopt(hCurl, CURLOPT_HEADERFUNCTION, WriteMemoryCallback); curl_easy_setopt(hCurl, CURLOPT_INFILESIZE, 0); // Content-Length curl_easy_setopt(hCurl, CURLOPT_HTTPHEADER, requestHeaders); + S3fsCurl::AddUserAgent(hCurl); // put User-Agent type = REQTYPE_COPYMULTIPOST; diff --git a/src/curl.h b/src/curl.h index 92b5db0..81d0bbc 100644 --- a/src/curl.h +++ b/src/curl.h @@ -205,6 +205,7 @@ class S3fsCurl static int max_parallel_cnt; static off_t multipart_size; static bool is_sigv4; + static bool is_ua; // User-Agent // variables CURL* hCurl; @@ -266,6 +267,7 @@ class S3fsCurl static bool LoadEnvSseCKeys(void); static bool LoadEnvSseKmsid(void); static bool PushbackSseKeys(std::string& onekey); + static bool AddUserAgent(CURL* hCurl); static int CurlDebugFunc(CURL* hcurl, curl_infotype type, char* data, size_t size, void* userptr); @@ -336,6 +338,8 @@ class S3fsCurl static off_t GetMultipartSize(void) { return S3fsCurl::multipart_size; } static bool SetSignatureV4(bool isset) { bool bresult = S3fsCurl::is_sigv4; S3fsCurl::is_sigv4 = isset; return bresult; } 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; } // methods bool CreateCurlHandle(bool force = false); diff --git a/src/s3fs.cpp b/src/s3fs.cpp index 999a547..c6c1075 100644 --- a/src/s3fs.cpp +++ b/src/s3fs.cpp @@ -4599,6 +4599,10 @@ static int my_fuse_opt_proc(void* data, const char* arg, int key, struct fuse_ar pathrequeststyle = true; return 0; } + if(0 == STR2NCMP(arg, "noua")){ + S3fsCurl::SetUserAgentFlag(false); + return 0; + } // // debug option for s3fs // diff --git a/src/s3fs_util.cpp b/src/s3fs_util.cpp index cc6197c..4c5d151 100644 --- a/src/s3fs_util.cpp +++ b/src/s3fs_util.cpp @@ -1109,6 +1109,12 @@ void show_help (void) " the virtual-host request style, by using the older path request\n" " style.\n" "\n" + " noua (suppress User-Agent header)\n" + " Usually s3fs outputs of the User-Agent in \"s3fs/ (commit\n" + " hash ; )\" format.\n" + " If this option is specified, s3fs suppresses the output of the\n" + " User-Agent.\n" + "\n" " dbglevel (default=\"crit\")\n" " Set the debug message level. set value as crit(critical), err\n" " (error), warn(warning), info(information) to debug level.\n"