Skip to content

Commit 7196e9b

Browse files
[HttpClient] fix binding to network interfaces
1 parent a647885 commit 7196e9b

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

CurlHttpClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public function request(string $method, string $url, array $options = []): Respo
269269
if ($options['bindto']) {
270270
if (file_exists($options['bindto'])) {
271271
$curlopts[\CURLOPT_UNIX_SOCKET_PATH] = $options['bindto'];
272-
} elseif (preg_match('/^(.*):(\d+)$/', $options['bindto'], $matches)) {
272+
} elseif (0 !== strpos($options['bindto'], 'if!') && preg_match('/^(.*):(\d+)$/', $options['bindto'], $matches)) {
273273
$curlopts[\CURLOPT_INTERFACE] = $matches[1];
274274
$curlopts[\CURLOPT_LOCALPORT] = $matches[2];
275275
} else {

NativeHttpClient.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,16 @@ public function request(string $method, string $url, array $options = []): Respo
6767
{
6868
[$url, $options] = self::prepareRequest($method, $url, $options, $this->defaultOptions);
6969

70-
if ($options['bindto'] && file_exists($options['bindto'])) {
71-
throw new TransportException(__CLASS__.' cannot bind to local Unix sockets, use e.g. CurlHttpClient instead.');
70+
if ($options['bindto']) {
71+
if (file_exists($options['bindto'])) {
72+
throw new TransportException(__CLASS__.' cannot bind to local Unix sockets, use e.g. CurlHttpClient instead.');
73+
}
74+
if (0 === strpos($options['bindto'], 'if!')) {
75+
throw new TransportException(__CLASS__.' cannot bind to network interfaces, use e.g. CurlHttpClient instead.');
76+
}
77+
if (0 === strpos($options['bindto'], 'host!')) {
78+
$options['bindto'] = substr($options['bindto'], 5);
79+
}
7280
}
7381

7482
$options['body'] = self::getBodyAsString($options['body']);

0 commit comments

Comments
 (0)