Skip to content

Commit

Permalink
fix(proxy): reaching s3 storage behind some http proxy
Browse files Browse the repository at this point in the history
Signed-off-by: Maxime Besson <maxime.besson@worteks.com>
  • Loading branch information
faust64 authored and maxbes committed Apr 9, 2021
1 parent 32551b9 commit 03fe74b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
10 changes: 9 additions & 1 deletion lib/private/Files/ObjectStore/S3ConnectionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ trait S3ConnectionTrait {
/** @var int */
protected $timeout;

/** @var string */
protected $proxy;

/** @var int */
protected $uploadPartSize;

Expand All @@ -71,6 +74,7 @@ protected function parseParams($params) {

$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'];
Expand All @@ -86,6 +90,10 @@ public function getBucket() {
return $this->bucket;
}

public function getProxy() {
return $this->proxy;
}

/**
* Returns the connection
*
Expand Down Expand Up @@ -123,7 +131,7 @@ public function getConnection() {
'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';
Expand Down
7 changes: 6 additions & 1 deletion lib/private/Files/ObjectStore/S3ObjectTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ abstract protected function getConnection();
*/
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,
Expand All @@ -70,6 +71,10 @@ public function readObject($urn) {
],
];

if ($connection->getProxy()) {
$opts['http']['proxy'] = $connection->getProxy();
}

$context = stream_context_create($opts);
return fopen($request->getUri(), 'r', false, $context);
});
Expand Down

0 comments on commit 03fe74b

Please sign in to comment.