Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set a default request timeout #16972

Merged
merged 2 commits into from
Sep 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/private/Http/Client/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
53 changes: 19 additions & 34 deletions tests/lib/Http/Client/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
}

Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -288,7 +271,8 @@ public function testSetDefaultOptionsWithNotInstalled(): void {
'proxy' => null,
'headers' => [
'User-Agent' => 'Nextcloud Server Crawler'
]
],
'timeout' => 30,
], self::invokePrivate($this->client, 'buildRequestOptions', [[]]));
}

Expand All @@ -314,7 +298,8 @@ public function testSetDefaultOptionsWithProxy(): void {
'proxy' => 'foo',
'headers' => [
'User-Agent' => 'Nextcloud Server Crawler'
]
],
'timeout' => 30,
], self::invokePrivate($this->client, 'buildRequestOptions', [[]]));
}
}