bug #38215 [HttpClient] Support for CURLOPT_LOCALPORT (derrabus)
This PR was merged into the 4.4 branch.
Discussion
----------
[HttpClient] Support for CURLOPT_LOCALPORT
| Q | A
| ------------- | ---
| Branch? | 4.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | https://github.com/symfony/symfony/issues/38081#issuecomment-688166943
| License | MIT
| Doc PR | N/A
Commits
-------
45fa6b8f24
[HttpClient] Support for CURLOPT_LOCALPORT.
This commit is contained in:
commit
ad226185af
@ -267,7 +267,14 @@ final class CurlHttpClient implements HttpClientInterface, LoggerAwareInterface,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($options['bindto']) {
|
if ($options['bindto']) {
|
||||||
$curlopts[file_exists($options['bindto']) ? \CURLOPT_UNIX_SOCKET_PATH : \CURLOPT_INTERFACE] = $options['bindto'];
|
if (file_exists($options['bindto'])) {
|
||||||
|
$curlopts[\CURLOPT_UNIX_SOCKET_PATH] = $options['bindto'];
|
||||||
|
} elseif (preg_match('/^(.*):(\d+)$/', $options['bindto'], $matches)) {
|
||||||
|
$curlopts[\CURLOPT_INTERFACE] = $matches[1];
|
||||||
|
$curlopts[\CURLOPT_LOCALPORT] = $matches[2];
|
||||||
|
} else {
|
||||||
|
$curlopts[\CURLOPT_INTERFACE] = $options['bindto'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 < $options['max_duration']) {
|
if (0 < $options['max_duration']) {
|
||||||
|
@ -35,6 +35,21 @@ class CurlHttpClientTest extends HttpClientTestCase
|
|||||||
return new CurlHttpClient();
|
return new CurlHttpClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testBindToPort()
|
||||||
|
{
|
||||||
|
$client = $this->getHttpClient(__FUNCTION__);
|
||||||
|
$response = $client->request('GET', 'http://localhost:8057', ['bindto' => '127.0.0.1:9876']);
|
||||||
|
$response->getStatusCode();
|
||||||
|
|
||||||
|
$r = new \ReflectionProperty($response, 'handle');
|
||||||
|
$r->setAccessible(true);
|
||||||
|
|
||||||
|
$curlInfo = curl_getinfo($r->getValue($response));
|
||||||
|
|
||||||
|
self::assertSame('127.0.0.1', $curlInfo['local_ip']);
|
||||||
|
self::assertSame(9876, $curlInfo['local_port']);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @requires PHP 7.2.17
|
* @requires PHP 7.2.17
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user