Skip to content

Commit

Permalink
Merge pull request #24 from jhiemstrawisc/fix-broken-path-urls
Browse files Browse the repository at this point in the history
Fix issues with virtual/path URLs
  • Loading branch information
jhiemstrawisc authored Apr 2, 2024
2 parents a77b8f5 + 732ca78 commit 42480c7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
19 changes: 15 additions & 4 deletions src/S3Commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <bucket> 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;
}

Expand Down
10 changes: 4 additions & 6 deletions src/S3Commands.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down

0 comments on commit 42480c7

Please sign in to comment.