diff --git a/src/curl.cpp b/src/curl.cpp index df68d98..66a730e 100644 --- a/src/curl.cpp +++ b/src/curl.cpp @@ -2900,6 +2900,37 @@ std::string S3fsCurl::CalcSignature(const std::string& method, const std::string return s3fs_hex_lower(md.get(), md_len); } +std::string S3fsCurl::extractURI(const std::string& url) { + // If the URL is empty, return "/" + if (url.empty()) { + return "/"; + } + + // Find the position of "://" + std::size_t protocol_pos = url.find("://"); + if (protocol_pos == std::string::npos) { + // If "://" is not found, return "/" + return "/"; + } + + // Find the position of the first "/" after "://" + std::size_t uri_pos = url.find('/', protocol_pos + 3); + if (uri_pos == std::string::npos) { + // If no "/" is found after the domain, return "/" + return "/"; + } + + // Extract the URI + std::string uri = url.substr(uri_pos); + + // Ensure the URI ends with "/" + if (uri.back() != '/') { + uri += '/'; + } + + return uri; +} + void S3fsCurl::insertV4Headers(const std::string& access_key_id, const std::string& secret_access_key, const std::string& access_token) { std::string server_path = type == REQTYPE::LISTBUCKET ? "/" : path; @@ -2944,7 +2975,7 @@ void S3fsCurl::insertV4Headers(const std::string& access_key_id, const std::stri get_date_sigv3(strdate, date8601); std::string contentSHA256 = payload_hash.empty() ? EMPTY_PAYLOAD_HASH : payload_hash; - const std::string realpath = pathrequeststyle ? "/" + S3fsCred::GetBucket() + server_path : server_path; + const std::string realpath = pathrequeststyle ? S3fsCurl::extractURI(s3host) + S3fsCred::GetBucket() + server_path : server_path; //string canonical_headers, signed_headers; requestHeaders = curl_slist_sort_insert(requestHeaders, "host", get_bucket_host().c_str()); diff --git a/src/curl.h b/src/curl.h index 042e45e..d6d40e3 100644 --- a/src/curl.h +++ b/src/curl.h @@ -233,6 +233,8 @@ class S3fsCurl static bool InitCryptMutex(); static bool DestroyCryptMutex(); static int CurlProgress(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow); + static std::string extractURI(const std::string& url); + static bool LocateBundle(); static size_t HeaderCallback(void *data, size_t blockSize, size_t numBlocks, void *userPtr);