in src/S3/S3MultiRegionClient.php [258:314]
private function determineRegionMiddleware()
{
return function (callable $handler) {
return function (CommandInterface $command) use ($handler) {
$cacheKey = $this->getCacheKey($command['Bucket']);
if (
empty($command['@region']) &&
$region = $this->cache->get($cacheKey)
) {
$command['@region'] = $region;
}
return Promise\Coroutine::of(function () use (
$handler,
$command,
$cacheKey
) {
try {
yield $handler($command);
} catch (PermanentRedirectException $e) {
if (empty($command['Bucket'])) {
throw $e;
}
$result = $e->getResult();
$region = null;
if (isset($result['@metadata']['headers']['x-amz-bucket-region'])) {
$region = $result['@metadata']['headers']['x-amz-bucket-region'];
$this->cache->set($cacheKey, $region);
} else {
$region = (yield $this->determineBucketRegionAsync(
$command['Bucket']
));
}
$command['@region'] = $region;
yield $handler($command);
} catch (AwsException $e) {
if ($e->getAwsErrorCode() === 'AuthorizationHeaderMalformed') {
$region = $this->determineBucketRegionFromExceptionBody(
$e->getResponse()
);
if (!empty($region)) {
$this->cache->set($cacheKey, $region);
$command['@region'] = $region;
yield $handler($command);
} else {
throw $e;
}
} else {
throw $e;
}
}
});
};
};
}