bug #44878 [HttpClient] Turn negative timeout to a very long timeout (fancyweb)

This PR was merged into the 4.4 branch.

Discussion
----------

[HttpClient] Turn negative timeout to a very long timeout

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | https://github.com/symfony/symfony/issues/44477
| License       | MIT
| Doc PR        | -

0 keeps on throwing.

Commits
-------

6360c316e5 [HttpClient] Turn negative timeout to a very long timeout
This commit is contained in:
Fabien Potencier 2022-01-01 15:47:42 +01:00
commit c8865409de
2 changed files with 13 additions and 1 deletions

View File

@ -147,7 +147,10 @@ trait HttpClientTrait
// 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];

View File

@ -179,4 +179,13 @@ abstract class HttpClientTestCase extends BaseHttpClientTestCase
$this->assertNotEmpty($traceInfo['debug']);
}
public function testNegativeTimeout()
{
$client = $this->getHttpClient(__FUNCTION__);
$this->assertSame(200, $client->request('GET', 'http://localhost:8057', [
'timeout' => -1,
])->getStatusCode());
}
}