From 99319c5b203b84d02a351ec20634dc9b6ca4a298 Mon Sep 17 00:00:00 2001 From: hedii Date: Wed, 14 Oct 2020 10:37:39 +0200 Subject: [PATCH] Add requestOptions to configuration --- README.md | 24 ++++++++++++++ src/OvhSwiftStorageServiceProvider.php | 1 + tests/RequestOptionsTest.php | 45 ++++++++++++++++++++++++++ tests/TestCase.php | 1 + 4 files changed, 71 insertions(+) create mode 100644 tests/RequestOptionsTest.php diff --git a/README.md b/README.md index ac9fc48..1bc4460 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ return [ 'visibility' => env('OVH_SWIFT_VISIBILITY', 'public'), 'publicUrl' => env('OVH_SWIFT_PUBLIC_URL'), 'urlKey' => env('OVH_SWIFT_URL_KEY'), + 'requestOptions' => [], ], ], @@ -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 diff --git a/src/OvhSwiftStorageServiceProvider.php b/src/OvhSwiftStorageServiceProvider.php index d3cc79d..03b6535 100644 --- a/src/OvhSwiftStorageServiceProvider.php +++ b/src/OvhSwiftStorageServiceProvider.php @@ -37,6 +37,7 @@ public function boot(FilesystemManager $filesystemManager, CacheRepository $cach ], ], 'publicUrl' => $this->getContainerPublicUrl($config), + 'requestOptions' => $config['requestOptions'] ?? [], ]; $openstack = new OpenStack($options); diff --git a/tests/RequestOptionsTest.php b/tests/RequestOptionsTest.php new file mode 100644 index 0000000..68b4fa6 --- /dev/null +++ b/tests/RequestOptionsTest.php @@ -0,0 +1,45 @@ +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); + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php index b13769e..db6e4d5 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -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);