diff --git a/src/S3Commands.cc b/src/S3Commands.cc index 6ea5858..8a445ba 100644 --- a/src/S3Commands.cc +++ b/src/S3Commands.cc @@ -59,22 +59,33 @@ bool AmazonRequest::parseURL( const std::string & url, std::string & path ) { auto i = url.find( "://" ); if( i == std::string::npos ) { return false; } - //protocol = substring( url, 0, i ); auto j = url.find( "/", i + 3 ); if( j == std::string::npos ) { if (style == "path") { + // If we're configured for path-style requests, then the host is everything between + // :// and the last / host = substring( url, i + 3 ); + // Likewise, the path is going to be /bucket/object + path = "/" + bucket + "/" + object; } else { + // In virtual-style requests, the host should be determined as everything between + // :// up until the last /, but with appended to the front. host = bucket + "." + substring( url, i + 3 ); + path = "/" + object; } - path = "/" + object; return true; } - host = bucket + "." + substring( url, i + 3, j ); - path = substring( url, j ) + object; + if (style == "path") { + host = substring( url, i + 3, j ); + path = substring( url, j ) + "/" + bucket + "/" + object; + } else { + host = bucket + "." + substring( url, i + 3, j ); + path = substring( url, j ) + object; + } + return true; } diff --git a/src/S3Commands.hh b/src/S3Commands.hh index 38e10a1..49a2aba 100644 --- a/src/S3Commands.hh +++ b/src/S3Commands.hh @@ -54,12 +54,10 @@ public: if( canonicalURI.empty() ) { canonicalURI = "/"; } // Now that we have the host and canonicalURI, we can build the actual url we perform the curl against. - // Using the previous example, we'd get a new hostUrl of "https://my-bucket.my-url.com:443/my-object". - if (style == "path") { - hostUrl = protocol + "://" + host + "/" + b + canonicalURI; - } else { - hostUrl = protocol + "://" + host + canonicalURI; - } + // Using the previous example, we'd get a new hostUrl of + // --> "https://my-bucket.my-url.com:443/my-object" for virtual style requests, and + // --> "https://my-url.com:443/my-bucket/my-object" for path style requests. + hostUrl = protocol + "://" + host + canonicalURI; // If we can, set the region based on the host. size_t secondDot = host.find( ".", 2 + 1 );