Skip to content

Commit 7694245

Browse files
[HttpClient] fix binding to network interfaces
1 parent fe36f35 commit 7694245

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/Symfony/Component/HttpClient/CurlHttpClient.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,11 @@ 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)) {
273+
$curlopts[\CURLOPT_INTERFACE] = $options['bindto'];
274+
} else {
273275
$curlopts[\CURLOPT_INTERFACE] = $matches[1];
274276
$curlopts[\CURLOPT_LOCALPORT] = $matches[2];
275-
} else {
276-
$curlopts[\CURLOPT_INTERFACE] = $options['bindto'];
277277
}
278278
}
279279

src/Symfony/Component/HttpClient/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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy