Skip to content

Commit 8d60e07

Browse files
committed
Merge branch '4.4' into 5.1
* 4.4: fix merge drop logger mock in favor of using the BufferingLogger catch ValueError thrown on PHP 8 [Yaml Parser] Fix edge cases when parsing multiple documents fix parsing comments not prefixed by a space [Translator] Make sure a null locale is handled properly deal with errors being thrown on PHP 8 [Cache] Allow cache tags to be objects implementing __toString() [HttpKernel] Do not override max_redirects option in HttpClientKernel remove superfluous cast [HttpClient] Support for CURLOPT_LOCALPORT. Upgrade PHPUnit to 8.5 (php 7.2) and 9.3 (php >= 7.3). Fixed exception message formatting [FrameworkBundle] Fix error in xsd which prevent to register more than one metadata [Console] work around disabled putenv() [PhpUnitBridge] Fix error with ReflectionClass [HttpClient][HttpClientTrait] don't calculate alternatives if option is auth_ntlm Change 'cache_key' to AbstractRendererEngine::CACHE_KEY_VAR Upgrade PHPUnit to 8.5 (php 7.2) and 9.3 (php >= 7.3).
2 parents 58546b6 + 505e0f6 commit 8d60e07

File tree

3 files changed

+86
-5
lines changed

3 files changed

+86
-5
lines changed

CurlHttpClient.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,14 @@ public function request(string $method, string $url, array $options = []): Respo
267267
}
268268

269269
if ($options['bindto']) {
270-
$curlopts[file_exists($options['bindto']) ? \CURLOPT_UNIX_SOCKET_PATH : \CURLOPT_INTERFACE] = $options['bindto'];
270+
if (file_exists($options['bindto'])) {
271+
$curlopts[\CURLOPT_UNIX_SOCKET_PATH] = $options['bindto'];
272+
} elseif (preg_match('/^(.*):(\d+)$/', $options['bindto'], $matches)) {
273+
$curlopts[\CURLOPT_INTERFACE] = $matches[1];
274+
$curlopts[\CURLOPT_LOCALPORT] = $matches[2];
275+
} else {
276+
$curlopts[\CURLOPT_INTERFACE] = $options['bindto'];
277+
}
271278
}
272279

273280
if (0 < $options['max_duration']) {

HttpClientTrait.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,16 @@ private static function mergeDefaultOptions(array $options, array $defaultOption
198198
continue;
199199
}
200200

201+
if ('auth_ntlm' === $name) {
202+
if (!\extension_loaded('curl')) {
203+
$msg = 'try installing the "curl" extension to use "%s" instead.';
204+
} else {
205+
$msg = 'try using "%s" instead.';
206+
}
207+
208+
throw new InvalidArgumentException(sprintf('Option "auth_ntlm" is not supported by "%s", '.$msg, __CLASS__, CurlHttpClient::class));
209+
}
210+
201211
$alternatives = [];
202212

203213
foreach ($defaultOptions as $key => $v) {
@@ -206,10 +216,6 @@ private static function mergeDefaultOptions(array $options, array $defaultOption
206216
}
207217
}
208218

209-
if ('auth_ntlm' === $name) {
210-
throw new InvalidArgumentException(sprintf('Option "auth_ntlm" is not supported by "%s", try using CurlHttpClient instead.', __CLASS__));
211-
}
212-
213219
throw new InvalidArgumentException(sprintf('Unsupported option "%s" passed to "%s", did you mean "%s"?', $name, __CLASS__, implode('", "', $alternatives ?: array_keys($defaultOptions))));
214220
}
215221

Tests/CurlHttpClientTest.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,74 @@ protected function getHttpClient(string $testCase): HttpClientInterface
3434
return new CurlHttpClient(['verify_peer' => false, 'verify_host' => false]);
3535
}
3636

37+
public function testBindToPort()
38+
{
39+
$client = $this->getHttpClient(__FUNCTION__);
40+
$response = $client->request('GET', 'http://localhost:8057', ['bindto' => '127.0.0.1:9876']);
41+
$response->getStatusCode();
42+
43+
$r = new \ReflectionProperty($response, 'handle');
44+
$r->setAccessible(true);
45+
46+
$curlInfo = curl_getinfo($r->getValue($response));
47+
48+
self::assertSame('127.0.0.1', $curlInfo['local_ip']);
49+
self::assertSame(9876, $curlInfo['local_port']);
50+
}
51+
52+
/**
53+
* @requires PHP 7.2.17
54+
*/
55+
public function testHttp2PushVulcain()
56+
{
57+
$client = $this->getVulcainClient();
58+
$logger = new TestLogger();
59+
$client->setLogger($logger);
60+
61+
$responseAsArray = $client->request('GET', 'https://127.0.0.1:3000/json', [
62+
'headers' => [
63+
'Preload' => '/documents/*/id',
64+
],
65+
])->toArray();
66+
67+
foreach ($responseAsArray['documents'] as $document) {
68+
$client->request('GET', 'https://127.0.0.1:3000'.$document['id'])->toArray();
69+
}
70+
71+
$client->reset();
72+
73+
$expected = [
74+
'Request: "GET https://127.0.0.1:3000/json"',
75+
'Queueing pushed response: "https://127.0.0.1:3000/json/1"',
76+
'Queueing pushed response: "https://127.0.0.1:3000/json/2"',
77+
'Queueing pushed response: "https://127.0.0.1:3000/json/3"',
78+
'Response: "200 https://127.0.0.1:3000/json"',
79+
'Accepting pushed response: "GET https://127.0.0.1:3000/json/1"',
80+
'Response: "200 https://127.0.0.1:3000/json/1"',
81+
'Accepting pushed response: "GET https://127.0.0.1:3000/json/2"',
82+
'Response: "200 https://127.0.0.1:3000/json/2"',
83+
'Accepting pushed response: "GET https://127.0.0.1:3000/json/3"',
84+
'Response: "200 https://127.0.0.1:3000/json/3"',
85+
];
86+
$this->assertSame($expected, $logger->logs);
87+
}
88+
89+
/**
90+
* @requires PHP 7.2.17
91+
*/
92+
public function testHttp2PushVulcainWithUnusedResponse()
93+
{
94+
$client = $this->getVulcainClient();
95+
$logger = new TestLogger();
96+
$client->setLogger($logger);
97+
98+
$responseAsArray = $client->request('GET', 'https://127.0.0.1:3000/json', [
99+
'headers' => [
100+
'Preload' => '/documents/*/id',
101+
],
102+
])->toArray();
103+
}
104+
37105
public function testTimeoutIsNotAFatalError()
38106
{
39107
if ('\\' === \DIRECTORY_SEPARATOR) {

0 commit comments

Comments
 (0)