8000 [HttpClient] Fix option "bindto" with IPv6 addresses · symfony/http-client@3852b38 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3852b38

Browse files
[HttpClient] Fix option "bindto" with IPv6 addresses
1 parent aae5019 commit 3852b38

File tree

3 files changed

+4
-17
lines changed

3 files changed

+4
-17
lines changed

CurlHttpClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ public function request(string $method, string $url, array $options = []): Respo
274274
if (file_exists($options['bindto'])) {
275275
$curlopts[\CURLOPT_UNIX_SOCKET_PATH] = $options['bindto'];
276276
} elseif (!str_starts_with($options['bindto'], 'if!') && preg_match('/^(.*):(\d+)$/', $options['bindto'], $matches)) {
277-
$curlopts[\CURLOPT_INTERFACE] = $matches[1];
277+
$curlopts[\CURLOPT_INTERFACE] = trim($matches[1], '[]');
278278
$curlopts[\CURLOPT_LOCALPORT] = $matches[2];
279279
} else {
280280
$curlopts[\CURLOPT_INTERFACE] = $options['bindto'];

NativeHttpClient.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,9 @@ private static function dnsResolve($host, NativeClientState $multi, array &$info
334334
$info['debug'] .= "* Hostname was NOT found in DNS cache\n";
335335
$now = microtime(true);
336336

337-
if (!$ip = gethostbynamel($host)) {
337+
if ('[' === $host[0] && ']' === $host[-1] && filter_var(substr($host, 1, -1), \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV6)) {
338+
$ip = [$host];
339+
} elseif (!$ip = gethostbynamel($host)) {
338340
throw new TransportException(sprintf('Could not resolve host "%s".', $host));
339341
}
340342

Tests/CurlHttpClientTest.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,6 @@ protected function getHttpClient(string $testCase): HttpClientInterface
3737
return new CurlHttpClient(['verify_peer' => false, 'verify_host' => false], 6, 50);
3838
}
3939

40-
public function testBindToPort()
41-
{
42-
$client = $this->getHttpClient(__FUNCTION__);
43-
$response = $client->request('GET', 'http://localhost:8057', ['bindto' => '127.0.0.1:9876']);
44-
$response->getStatusCode();
45-
46-
$r = new \ReflectionProperty($response, 'handle');
47-
$r->setAccessible(true);
48-
49-
$curlInfo = curl_getinfo($r->getValue($response));
50-
51-
self::assertSame('127.0.0.1', $curlInfo['local_ip']);
52-
self::assertSame(9876, $curlInfo['local_port']);
53-
}
54-
5540
public function testTimeoutIsNotAFatalError()
5641
{
5742
if ('\\' === \DIRECTORY_SEPARATOR) {

0 commit comments

Comments
 (0)
< 10C5 template id="site-details-dialog">
0