Skip to content

Commit

Permalink
Merge pull request #107 from utopia-php/feat-set-curl-http-version
Browse files Browse the repository at this point in the history
PEA-649 allow setting http version in s3 adapter
  • Loading branch information
lohanidamodar authored Apr 2, 2024
2 parents faa0279 + 33ea0fb commit 94ab875
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
41 changes: 39 additions & 2 deletions src/Storage/Device/S3.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ class S3 extends Device

const METHOD_TRACE = 'TRACE';

const HTTP_VERSION_1_1 = CURL_HTTP_VERSION_1_1;

const HTTP_VERSION_2_0 = CURL_HTTP_VERSION_2_0;

const HTTP_VERSION_2 = CURL_HTTP_VERSION_2;

const HTTP_VERSION_1_0 = CURL_HTTP_VERSION_1_0;

/**
* AWS Regions constants
*/
Expand Down Expand Up @@ -138,6 +146,13 @@ class S3 extends Device
*/
protected array $amzHeaders;

/**
* Http version
*
* @var int|null
*/
protected ?int $curlHttpVersion = null;

/**
* S3 Constructor
*
Expand Down Expand Up @@ -208,6 +223,20 @@ public function getPath(string $filename, string $prefix = null): string
return $this->getRoot().DIRECTORY_SEPARATOR.$filename;
}

/**
* Set http version
*
*
* @param int|null $httpVersion
* @return self
*/
public function setHttpVersion(?int $httpVersion): self
{
$this->curlHttpVersion = $httpVersion;

return $this;
}

/**
* Upload.
*
Expand Down Expand Up @@ -483,7 +512,7 @@ public function delete(string $path, bool $recursive = false): bool
*
* @throws Exception
*/
private function listObjects(string $prefix = '', int $maxKeys = self::MAX_PAGE_SIZE, string $continuationToken = ''): array
protected function listObjects(string $prefix = '', int $maxKeys = self::MAX_PAGE_SIZE, string $continuationToken = ''): array
{
if ($maxKeys > self::MAX_PAGE_SIZE) {
throw new Exception('Cannot list more than '.self::MAX_PAGE_SIZE.' objects');
Expand All @@ -494,6 +523,9 @@ private function listObjects(string $prefix = '', int $maxKeys = self::MAX_PAGE_
$this->headers['content-type'] = 'text/plain';
$this->headers['content-md5'] = \base64_encode(md5('', true));

unset($this->amzHeaders['x-amz-content-sha256']);
unset($this->amzHeaders['x-amz-acl']);

$parameters = [
'list-type' => 2,
'prefix' => $prefix,
Expand Down Expand Up @@ -797,7 +829,7 @@ private function getSignatureV4(string $method, string $uri, array $parameters =
*
* @throws \Exception
*/
private function call(string $method, string $uri, string $data = '', array $parameters = [], bool $decode = true)
protected function call(string $method, string $uri, string $data = '', array $parameters = [], bool $decode = true)
{
$uri = $this->getAbsolutePath($uri);
$url = 'https://'.$this->headers['host'].$uri.'?'.\http_build_query($parameters, '', '&', PHP_QUERY_RFC3986);
Expand Down Expand Up @@ -837,6 +869,11 @@ private function call(string $method, string $uri, string $data = '', array $par
\curl_setopt($curl, CURLOPT_HTTPHEADER, $httpHeaders);
\curl_setopt($curl, CURLOPT_HEADER, false);
\curl_setopt($curl, CURLOPT_RETURNTRANSFER, false);

if ($this->curlHttpVersion != null) {
\curl_setopt($curl, CURLOPT_HTTP_VERSION, $this->curlHttpVersion);
}

\curl_setopt($curl, CURLOPT_WRITEFUNCTION, function ($curl, string $data) use ($response) {
$response->body .= $data;

Expand Down
2 changes: 1 addition & 1 deletion tests/Storage/Device/BackblazeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ protected function init(): void
$this->root = '/root';
$key = $_SERVER['BACKBLAZE_ACCESS_KEY'] ?? '';
$secret = $_SERVER['BACKBLAZE_SECRET'] ?? '';
$bucket = 'utopia-storage-test';
$bucket = 'utopia-storage-test-new';

$this->object = new Backblaze($this->root, $key, $secret, $bucket, Backblaze::US_WEST_004, Backblaze::ACL_PRIVATE);
}
Expand Down

0 comments on commit 94ab875

Please sign in to comment.