Skip to content

Commit

Permalink
Add requestOptions to configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
hedii committed Oct 14, 2020
1 parent 45eec83 commit 99319c5
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ return [
'visibility' => env('OVH_SWIFT_VISIBILITY', 'public'),
'publicUrl' => env('OVH_SWIFT_PUBLIC_URL'),
'urlKey' => env('OVH_SWIFT_URL_KEY'),
'requestOptions' => [],
],

],
Expand Down Expand Up @@ -80,6 +81,29 @@ OVH_SWIFT_URL_KEY=xxxxxxxxxxxxxxxxxxx

Be aware you will not be able to retrieve regular urls with a private container, only temporary urls.

### Request options

If you want to use http [request options](https://docs.guzzlephp.org/en/6.5/request-options.html#on-headers) like `timeout`, `connect_timeout` or any other valid option, put them in the driver configuration.

```php
return [

'disks' => [
/* ... */

'ovh-swift' => [
/* ... */
'requestOptions' => [
'timeout' => 3.14,
'connect_timeout' => 3.14,
],
],

],

];
```

### Example

```php
Expand Down
1 change: 1 addition & 0 deletions src/OvhSwiftStorageServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function boot(FilesystemManager $filesystemManager, CacheRepository $cach
],
],
'publicUrl' => $this->getContainerPublicUrl($config),
'requestOptions' => $config['requestOptions'] ?? [],
];

$openstack = new OpenStack($options);
Expand Down
45 changes: 45 additions & 0 deletions tests/RequestOptionsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Hedii\LaravelOvhSwiftStorage\Tests;

use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;

class RequestOptionsTest extends TestCase
{
protected string $tempDir = __DIR__ . '/temp';

public function setUp(): void
{
parent::setUp();

if (! is_dir($this->tempDir)) {
mkdir($this->tempDir);
}
}

public function tearDown(): void
{
parent::tearDown();

exec("rm -rf {$this->tempDir}");
}

public function testItShouldUseRequestOptions(): void
{
$path = $this->tempDir . '/' . Str::random() . '.txt';

$this->app['config']->set('filesystems.disks.ovh-swift', $this->getOvhSwiftConfiguration([
'requestOptions' => [
'on_headers' => fn(): bool => touch($path)
]
]));

$fileName = $this->randomFileName();
$content = $this->randomContent();

Storage::put($fileName, $content);

$this->assertFileExists($path);
}
}
1 change: 1 addition & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ protected function getOvhSwiftConfiguration(array $config = []): array
'visibility' => env('OVH_SWIFT_VISIBILITY', 'public'),
'publicUrl' => env('OVH_SWIFT_PUBLIC_URL'),
'urlKey' => env('OVH_SWIFT_URL_KEY'),
'requestOptions' => [],
];

return array_merge($baseConfig, $config);
Expand Down

0 comments on commit 99319c5

Please sign in to comment.