From 03fe74b95e23df70d3cd4815a84b6fa22a06ee81 Mon Sep 17 00:00:00 2001 From: Samuel Date: Sat, 13 Mar 2021 12:05:27 +0100 Subject: [PATCH 1/2] fix(proxy): reaching s3 storage behind some http proxy Signed-off-by: Maxime Besson --- lib/private/Files/ObjectStore/S3ConnectionTrait.php | 10 +++++++++- lib/private/Files/ObjectStore/S3ObjectTrait.php | 7 ++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/private/Files/ObjectStore/S3ConnectionTrait.php b/lib/private/Files/ObjectStore/S3ConnectionTrait.php index d88ef0ac8e..6fd6b14aab 100644 --- a/lib/private/Files/ObjectStore/S3ConnectionTrait.php +++ b/lib/private/Files/ObjectStore/S3ConnectionTrait.php @@ -57,6 +57,9 @@ trait S3ConnectionTrait { /** @var int */ protected $timeout; + /** @var string */ + protected $proxy; + /** @var int */ protected $uploadPartSize; @@ -71,6 +74,7 @@ trait S3ConnectionTrait { $this->test = isset($params['test']); $this->bucket = $params['bucket']; + $this->proxy = isset($params['proxy']) ? $params['proxy'] : false; $this->timeout = !isset($params['timeout']) ? 15 : $params['timeout']; $this->uploadPartSize = !isset($params['uploadPartSize']) ? 524288000 : $params['uploadPartSize']; $params['region'] = empty($params['region']) ? 'eu-west-1' : $params['region']; @@ -86,6 +90,10 @@ trait S3ConnectionTrait { return $this->bucket; } + public function getProxy() { + return $this->proxy; + } + /** * Returns the connection * @@ -123,7 +131,7 @@ trait S3ConnectionTrait { 'csm' => false, ]; if (isset($this->params['proxy'])) { - $options['request.options'] = ['proxy' => $this->params['proxy']]; + $options['http'] = [ 'proxy' => $this->params['proxy'] ]; } if (isset($this->params['legacy_auth']) && $this->params['legacy_auth']) { $options['signature_version'] = 'v2'; diff --git a/lib/private/Files/ObjectStore/S3ObjectTrait.php b/lib/private/Files/ObjectStore/S3ObjectTrait.php index 4d6ac3608d..3f9d86f8e2 100644 --- a/lib/private/Files/ObjectStore/S3ObjectTrait.php +++ b/lib/private/Files/ObjectStore/S3ObjectTrait.php @@ -51,7 +51,8 @@ trait S3ObjectTrait { */ public function readObject($urn) { return SeekableHttpStream::open(function ($range) use ($urn) { - $command = $this->getConnection()->getCommand('GetObject', [ + $connection = $this->getConnection(); + $command = $connection->getCommand('GetObject', [ 'Bucket' => $this->bucket, 'Key' => $urn, 'Range' => 'bytes=' . $range, @@ -70,6 +71,10 @@ trait S3ObjectTrait { ], ]; + if ($connection->getProxy()) { + $opts['http']['proxy'] = $connection->getProxy(); + } + $context = stream_context_create($opts); return fopen($request->getUri(), 'r', false, $context); }); From 547438527d5184f786117a21f65ca51b95ee695c Mon Sep 17 00:00:00 2001 From: Maxime Besson Date: Thu, 8 Apr 2021 18:00:12 +0200 Subject: [PATCH 2/2] fix(proxy): reaching s3 storage behind some http proxy Signed-off-by: Maxime Besson --- lib/private/Files/ObjectStore/S3ObjectTrait.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/private/Files/ObjectStore/S3ObjectTrait.php b/lib/private/Files/ObjectStore/S3ObjectTrait.php index 3f9d86f8e2..9e23997d6d 100644 --- a/lib/private/Files/ObjectStore/S3ObjectTrait.php +++ b/lib/private/Files/ObjectStore/S3ObjectTrait.php @@ -51,8 +51,7 @@ trait S3ObjectTrait { */ public function readObject($urn) { return SeekableHttpStream::open(function ($range) use ($urn) { - $connection = $this->getConnection(); - $command = $connection->getCommand('GetObject', [ + $command = $this->getConnection()->getCommand('GetObject', [ 'Bucket' => $this->bucket, 'Key' => $urn, 'Range' => 'bytes=' . $range, @@ -71,8 +70,9 @@ trait S3ObjectTrait { ], ]; - if ($connection->getProxy()) { - $opts['http']['proxy'] = $connection->getProxy(); + if ($this->getProxy()) { + $opts['http']['proxy'] = $this->getProxy(); + $opts['http']['request_fulluri'] = true; } $context = stream_context_create($opts);