8000 [HttpClient] Turn negative timeout to a very long timeout by fancyweb · Pull Request #44878 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpClient] Turn negative timeout to a very long timeout #44878

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

Merged
merged 1 commit into from
Jan 1, 2022
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
10000
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[HttpClient] Turn negative timeout to a very long timeout
  • Loading branch information
fancyweb committed Dec 31, 2021
commit 6360c316e520a4b08813af656817c80d07033316
5 changes: 4 additions & 1 deletion src/Symfony/Component/HttpClient/HttpClientTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ private static function prepareRequest(?string $method, ?string $url, array $opt

// Finalize normalization of options
$options['http_version'] = (string) ($options['http_version'] ?? '') ?: null;
$options['timeout'] = (float) ($options['timeout'] ?? ini_get('default_socket_timeout'));
if (0 > $options['timeout'] = (float) ($options['timeout'] ?? ini_get('default_socket_timeout'))) {
$options['timeout'] = 172800.0; // 2 days
}

$options['max_duration'] = isset($options['max_duration']) ? (float) $options['max_duration'] : 0;

return [$url, $options];
Expand Down
80F3
9 changes: 9 additions & 0 deletions src/Symfony/Component/HttpClient/Tests/HttpClientTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,13 @@ public function testDebugInfoOnDestruct()

$this->assertNotEmpty($traceInfo['debug']);
}

public function testNegativeTimeout()
{
$client = $this->getHttpClient(__FUNCTION__);

$this->assertSame(200, $client->request('GET', 'http://localhost:8057', [
'timeout' => -1,
])->getStatusCode());
}
}
0