8000 [HttpClient] fix binding to network interfaces · symfony/symfony@02d1632 · GitHub
[go: up one dir, main page]

Skip to content

Commit 02d1632

Browse files
[HttpClient] fix binding to network interfaces
1 parent 441ceec commit 02d1632

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/Symfony/Component/HttpClient/AmpHttpClient.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ public function request(string $method, string $url, array $options = []): Respo
8282
throw new \LogicException('You cannot use the "proxy" option as the "amphp/http-tunnel" package is not installed. Try running "composer require amphp/http-tunnel".');
8383
}
8484

85+
if ($options['bindto']) {
86+
if (0 === strpos($options['bindto'], 'if!')) {
87+
throw new TransportException(__CLASS__.' cannot bind to network interfaces, use e.g. CurlHttpClient instead.');
88+
}
89+
if (0 === strpos($options['bindto'], 'host!')) {
90+
$options['bindto'] = substr($options['bindto'], 5);
91+
}
92+
}
93+
8594
if ('' !== $options['body'] && 'POST' === $method && !isset($options['normalized_headers']['content-type'])) {
8695
$options['headers'][] = 'Content-Type: application/x-www-form-urlencoded';
8796
}
@@ -141,7 +150,7 @@ public function stream($responses, float $timeout = null): ResponseStreamInterfa
141150
if ($responses instanceof AmpResponse) {
142151
$responses = [$responses];
143152
} elseif (!is_iterable($responses)) {
144-
throw new \TypeError(sprintf('%s() expects parameter 1 to be an iterable of AmpResponse objects, %s given.', __METHOD__, get_debug_type($responses)));
153+
throw new \TypeError(sprintf('"%s()" expects parameter 1 to be an iterable of AmpResponse objects, "%s" given.', __METHOD__, get_debug_type($responses)));
145154
}
146155

147156
return new ResponseStream(AmpResponse::stream($responses, $timeout));

src/Symfony/Component/HttpClient/Internal/AmpClientState.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function request(array $options, Request $request, CancellationToken $can
119119
private function getClient(array $options): array
120120
{
121121
$options = [
122-
'bindto' => $options['bindto'] ?: '0',
122+
'bindto' => $options['bindto'] ?: '0:0',
123123
'verify_peer' => $options['verify_peer'],
124124
'capath' => $options['capath'],
125125
'cafile' => $options['cafile'],

0 commit comments

Comments
 (0)
0