Skip to content

Commit c886540

Browse files
committed
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 | #44477 | License | MIT | Doc PR | - 0 keeps on throwing. Commits ------- 6360c31 [HttpClient] Turn negative timeout to a very long timeout
2 parents 69d4d6d + 6360c31 commit c886540

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/Symfony/Component/HttpClient/HttpClientTrait.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,10 @@ private static function prepareRequest(?string $method, ?string $url, array $opt
147147

148148
// Finalize normalization of options
149149
$options['http_version'] = (string) ($options['http_version'] ?? '') ?: null;
150-
$options['timeout'] = (float) ($options['timeout'] ?? ini_get('default_socket_timeout'));
150+
if (0 > $options['timeout'] = (float) ($options['timeout'] ?? ini_get('default_socket_timeout'))) {
151+
$options['timeout'] = 172800.0; // 2 days
152+
}
153+
151154
$options['max_duration'] = isset($options['max_duration']) ? (float) $options['max_duration'] : 0;
152155

153156
return [$url, $options];

src/Symfony/Component/HttpClient/Tests/HttpClientTestCase.php

+9
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,13 @@ public function testDebugInfoOnDestruct()
179179

180180
$this->assertNotEmpty($traceInfo['debug']);
181181
}
182+
183+
public function testNegativeTimeout()
184+
{
185+
$client = $this->getHttpClient(__FUNCTION__);
186+
187+
$this->assertSame(200, $client->request('GET', 'http://localhost:8057', [
188+
'timeout' => -1,
189+
])->getStatusCode());
190+
}
182191
}

0 commit comments

Comments
 (0)