[HttpClient] fix binding to network interfaces
This commit is contained in:
parent
fe36f35d9b
commit
faa1fd32f9
@ -269,7 +269,7 @@ final class CurlHttpClient implements HttpClientInterface, LoggerAwareInterface,
|
|||||||
if ($options['bindto']) {
|
if ($options['bindto']) {
|
||||||
if (file_exists($options['bindto'])) {
|
if (file_exists($options['bindto'])) {
|
||||||
$curlopts[\CURLOPT_UNIX_SOCKET_PATH] = $options['bindto'];
|
$curlopts[\CURLOPT_UNIX_SOCKET_PATH] = $options['bindto'];
|
||||||
} elseif (preg_match('/^(.*):(\d+)$/', $options['bindto'], $matches)) {
|
} elseif (0 !== strpos($options['bindto'], 'if!') && preg_match('/^(.*):(\d+)$/', $options['bindto'], $matches)) {
|
||||||
$curlopts[\CURLOPT_INTERFACE] = $matches[1];
|
$curlopts[\CURLOPT_INTERFACE] = $matches[1];
|
||||||
$curlopts[\CURLOPT_LOCALPORT] = $matches[2];
|
$curlopts[\CURLOPT_LOCALPORT] = $matches[2];
|
||||||
} else {
|
} else {
|
||||||
|
@ -67,8 +67,16 @@ final class NativeHttpClient implements HttpClientInterface, LoggerAwareInterfac
|
|||||||
{
|
{
|
||||||
[$url, $options] = self::prepareRequest($method, $url, $options, $this->defaultOptions);
|
[$url, $options] = self::prepareRequest($method, $url, $options, $this->defaultOptions);
|
||||||
|
|
||||||
if ($options['bindto'] && file_exists($options['bindto'])) {
|
if ($options['bindto']) {
|
||||||
throw new TransportException(__CLASS__.' cannot bind to local Unix sockets, use e.g. CurlHttpClient instead.');
|
if (file_exists($options['bindto'])) {
|
||||||
|
throw new TransportException(__CLASS__.' cannot bind to local Unix sockets, use e.g. CurlHttpClient instead.');
|
||||||
|
}
|
||||||
|
if (0 === strpos($options['bindto'], 'if!')) {
|
||||||
|
throw new TransportException(__CLASS__.' cannot bind to network interfaces, use e.g. CurlHttpClient instead.');
|
||||||
|
}
|
||||||
|
if (0 === strpos($options['bindto'], 'host!')) {
|
||||||
|
$options['bindto'] = substr($options['bindto'], 5);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$options['body'] = self::getBodyAsString($options['body']);
|
$options['body'] = self::getBodyAsString($options['body']);
|
||||||
|
Reference in New Issue
Block a user