summaryrefslogtreecommitdiff
path: root/vendor/aws/aws-sdk-php/src/S3/PermanentRedirectMiddleware.php
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2022-11-23 21:14:33 +0300
committerAndrew Dolgov <[email protected]>2022-11-23 21:14:33 +0300
commit0c8af4992cb0f7589dcafaad65ada12753c64594 (patch)
tree18e83d068c3e7dd2499331de977782b382279396 /vendor/aws/aws-sdk-php/src/S3/PermanentRedirectMiddleware.php
initial
Diffstat (limited to 'vendor/aws/aws-sdk-php/src/S3/PermanentRedirectMiddleware.php')
-rw-r--r--vendor/aws/aws-sdk-php/src/S3/PermanentRedirectMiddleware.php62
1 files changed, 62 insertions, 0 deletions
diff --git a/vendor/aws/aws-sdk-php/src/S3/PermanentRedirectMiddleware.php b/vendor/aws/aws-sdk-php/src/S3/PermanentRedirectMiddleware.php
new file mode 100644
index 0000000..eb4b8e3
--- /dev/null
+++ b/vendor/aws/aws-sdk-php/src/S3/PermanentRedirectMiddleware.php
@@ -0,0 +1,62 @@
+<?php
+namespace Aws\S3;
+
+use Aws\CommandInterface;
+use Aws\ResultInterface;
+use Aws\S3\Exception\PermanentRedirectException;
+use Psr\Http\Message\RequestInterface;
+
+/**
+ * Throws a PermanentRedirectException exception when a 301 redirect is
+ * encountered.
+ *
+ * @internal
+ */
+class PermanentRedirectMiddleware
+{
+ /** @var callable */
+ private $nextHandler;
+
+ /**
+ * Create a middleware wrapper function.
+ *
+ * @return callable
+ */
+ public static function wrap()
+ {
+ return function (callable $handler) {
+ return new self($handler);
+ };
+ }
+
+ /**
+ * @param callable $nextHandler Next handler to invoke.
+ */
+ public function __construct(callable $nextHandler)
+ {
+ $this->nextHandler = $nextHandler;
+ }
+
+ public function __invoke(CommandInterface $command, RequestInterface $request = null)
+ {
+ $next = $this->nextHandler;
+ return $next($command, $request)->then(
+ function (ResultInterface $result) use ($command) {
+ $status = isset($result['@metadata']['statusCode'])
+ ? $result['@metadata']['statusCode']
+ : null;
+ if ($status == 301) {
+ throw new PermanentRedirectException(
+ 'Encountered a permanent redirect while requesting '
+ . $result->search('"@metadata".effectiveUri') . '. '
+ . 'Are you sure you are using the correct region for '
+ . 'this bucket?',
+ $command,
+ ['result' => $result]
+ );
+ }
+ return $result;
+ }
+ );
+ }
+}