From ca2623e6ad4f7d838a61c71ba828b44b3b7331ab Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Mon, 2 Sep 2019 15:42:48 +0200 Subject: [PATCH 1/2] Set a default request timeout This to avoid endless running processes. A default timeout of 30 seconds should cover the 99% case. If a job need specific longer time it should set that. Signed-off-by: Roeland Jago Douma --- lib/private/Http/Client/Client.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/private/Http/Client/Client.php b/lib/private/Http/Client/Client.php index 993b83917fd3a..28694f3858502 100644 --- a/lib/private/Http/Client/Client.php +++ b/lib/private/Http/Client/Client.php @@ -63,6 +63,7 @@ private function buildRequestOptions(array $options): array { $defaults = [ RequestOptions::PROXY => $this->getProxyUri(), RequestOptions::VERIFY => $this->getCertBundle(), + RequestOptions::TIMEOUT => 30, ]; $options = array_merge($defaults, $options); From 773778dd8ce6a483539414add1d0a440233e5cad Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Tue, 3 Sep 2019 09:14:08 +0200 Subject: [PATCH 2/2] Add default timeout to expected request options Signed-off-by: Daniel Kesselberg --- tests/lib/Http/Client/ClientTest.php | 53 ++++++++++------------------ 1 file changed, 19 insertions(+), 34 deletions(-) diff --git a/tests/lib/Http/Client/ClientTest.php b/tests/lib/Http/Client/ClientTest.php index 7a25acd9a5033..5c0693732bc20 100644 --- a/tests/lib/Http/Client/ClientTest.php +++ b/tests/lib/Http/Client/ClientTest.php @@ -111,8 +111,9 @@ private function setUpDefaultRequestOptions(): void { 'verify' => '/my/path.crt', 'proxy' => 'foo', 'headers' => [ - 'User-Agent' => 'Nextcloud Server Crawler' - ] + 'User-Agent' => 'Nextcloud Server Crawler', + ], + 'timeout' => 30, ]; } @@ -128,13 +129,10 @@ public function testGet(): void { public function testGetWithOptions(): void { $this->setUpDefaultRequestOptions(); - $options = [ + $options = array_merge($this->defaultRequestOptions, [ 'verify' => false, 'proxy' => 'bar', - 'headers' => [ - 'User-Agent' => 'Nextcloud Server Crawler' - ] - ]; + ]); $this->guzzleClient->method('request') ->with('get', 'http://localhost/', $options) @@ -154,13 +152,10 @@ public function testPost(): void { public function testPostWithOptions(): void { $this->setUpDefaultRequestOptions(); - $options = [ + $options = array_merge($this->defaultRequestOptions, [ 'verify' => false, 'proxy' => 'bar', - 'headers' => [ - 'User-Agent' => 'Nextcloud Server Crawler' - ] - ]; + ]); $this->guzzleClient->method('request') ->with('post', 'http://localhost/', $options) @@ -180,13 +175,10 @@ public function testPut(): void { public function testPutWithOptions(): void { $this->setUpDefaultRequestOptions(); - $options = [ + $options = array_merge($this->defaultRequestOptions, [ 'verify' => false, 'proxy' => 'bar', - 'headers' => [ - 'User-Agent' => 'Nextcloud Server Crawler' - ] - ]; + ]); $this->guzzleClient->method('request') ->with('put', 'http://localhost/', $options) @@ -206,13 +198,10 @@ public function testDelete(): void { public function testDeleteWithOptions(): void { $this->setUpDefaultRequestOptions(); - $options = [ + $options = array_merge($this->defaultRequestOptions, [ 'verify' => false, 'proxy' => 'bar', - 'headers' => [ - 'User-Agent' => 'Nextcloud Server Crawler' - ] - ]; + ]); $this->guzzleClient->method('request') ->with('delete', 'http://localhost/', $options) @@ -232,13 +221,10 @@ public function testOptions(): void { public function testOptionsWithOptions(): void { $this->setUpDefaultRequestOptions(); - $options = [ + $options = array_merge($this->defaultRequestOptions, [ 'verify' => false, 'proxy' => 'bar', - 'headers' => [ - 'User-Agent' => 'Nextcloud Server Crawler' - ] - ]; + ]); $this->guzzleClient->method('request') ->with('options', 'http://localhost/', $options) @@ -258,13 +244,10 @@ public function testHead(): void { public function testHeadWithOptions(): void { $this->setUpDefaultRequestOptions(); - $options = [ + $options = array_merge($this->defaultRequestOptions, [ 'verify' => false, 'proxy' => 'bar', - 'headers' => [ - 'User-Agent' => 'Nextcloud Server Crawler' - ] - ]; + ]); $this->guzzleClient->method('request') ->with('head', 'http://localhost/', $options) @@ -288,7 +271,8 @@ public function testSetDefaultOptionsWithNotInstalled(): void { 'proxy' => null, 'headers' => [ 'User-Agent' => 'Nextcloud Server Crawler' - ] + ], + 'timeout' => 30, ], self::invokePrivate($this->client, 'buildRequestOptions', [[]])); } @@ -314,7 +298,8 @@ public function testSetDefaultOptionsWithProxy(): void { 'proxy' => 'foo', 'headers' => [ 'User-Agent' => 'Nextcloud Server Crawler' - ] + ], + 'timeout' => 30, ], self::invokePrivate($this->client, 'buildRequestOptions', [[]])); } }