Skip to content

Commit 95f4f0f

Browse files
committed
Dirty workaround to resolve correct endpoint in HEAD requests
1 parent 85ea912 commit 95f4f0f

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/IO/S3/Client.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ Model::HeadObjectOutcome Client::HeadObject(HeadObjectRequest & request) const
373373
auto bucket_uri = getURIForBucket(bucket);
374374
if (!bucket_uri)
375375
{
376-
if (auto maybe_error = updateURIForBucketForHead(bucket); maybe_error.has_value())
376+
if (auto maybe_error = updateURIForBucketForHead(bucket, request.GetKey()); maybe_error.has_value())
377377
return *maybe_error;
378378

379379
if (auto region = getRegionForBucket(bucket); !region.empty())
@@ -578,7 +578,6 @@ Client::doRequest(RequestType & request, RequestFn request_fn) const
578578
if (auto uri = getURIForBucket(bucket); uri.has_value())
579579
request.overrideURI(std::move(*uri));
580580

581-
582581
bool found_new_endpoint = false;
583582
// if we found correct endpoint after 301 responses, update the cache for future requests
584583
SCOPE_EXIT(
@@ -813,12 +812,15 @@ std::optional<S3::URI> Client::getURIFromError(const Aws::S3::S3Error & error) c
813812
}
814813

815814
// Do a list request because head requests don't have body in response
816-
std::optional<Aws::S3::S3Error> Client::updateURIForBucketForHead(const std::string & bucket) const
815+
// S3 Tables don't support ListObjects, so made dirty workaroung - changed on GetObject
816+
std::optional<Aws::S3::S3Error> Client::updateURIForBucketForHead(const std::string & bucket, const std::string & key) const
817817
{
818-
ListObjectsV2Request req;
818+
GetObjectRequest req;
819819
req.SetBucket(bucket);
820-
req.SetMaxKeys(1);
821-
auto result = ListObjectsV2(req);
820+
req.SetKey(key);
821+
req.SetRange("bytes=0-1");
822+
auto result = GetObject(req);
823+
822824
if (result.IsSuccess())
823825
return std::nullopt;
824826
return result.GetError();

src/IO/S3/Client.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ class Client : private Aws::S3::S3Client
269269

270270
void updateURIForBucket(const std::string & bucket, S3::URI new_uri) const;
271271
std::optional<S3::URI> getURIFromError(const Aws::S3::S3Error & error) const;
272-
std::optional<Aws::S3::S3Error> updateURIForBucketForHead(const std::string & bucket) const;
272+
std::optional<Aws::S3::S3Error> updateURIForBucketForHead(const std::string & bucket, const std::string & key) const;
273273

274274
std::optional<S3::URI> getURIForBucket(const std::string & bucket) const;
275275

0 commit comments

Comments
 (0)