Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit87c5be9

Browse files
[HttpClient] madeHttpClient::create() return anAmpHttpClient whenamphp/http-client is found but curl is not or too old
1 parent49e5d57 commit87c5be9

File tree

5 files changed

+32
-5
lines changed

5 files changed

+32
-5
lines changed

‎src/Symfony/Component/HttpClient/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ CHANGELOG
77
* added`NoPrivateNetworkHttpClient` decorator
88
* added`AmpHttpClient`, a portable HTTP/2 implementation based on Amp
99
* added`LoggerAwareInterface` to`ScopingHttpClient` and`TraceableHttpClient`
10+
* made`HttpClient::create()` return an`AmpHttpClient` when`amphp/http-client` is found but curl is not or too old
1011

1112
4.4.0
1213
-----

‎src/Symfony/Component/HttpClient/HttpClient.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespaceSymfony\Component\HttpClient;
1313

14+
useAmp\Http\Client\Connection\ConnectionLimitingPool;
1415
useSymfony\Contracts\HttpClient\HttpClientInterface;
1516

1617
/**
@@ -29,6 +30,25 @@ final class HttpClient
2930
*/
3031
publicstaticfunctioncreate(array$defaultOptions = [],int$maxHostConnections =6,int$maxPendingPushes =50):HttpClientInterface
3132
{
33+
if ($amp =class_exists(ConnectionLimitingPool::class)) {
34+
if (!\extension_loaded('curl')) {
35+
returnnewAmpHttpClient($defaultOptions,null,$maxHostConnections,$maxPendingPushes);
36+
}
37+
38+
// Skip curl when HTTP/2 push is unsupported or buggy, see https://bugs.php.net/77535
39+
if (\PHP_VERSION_ID <70217 || (\PHP_VERSION_ID >=70300 && \PHP_VERSION_ID <70304) || !\defined('CURLMOPT_PUSHFUNCTION')) {
40+
returnnewAmpHttpClient($defaultOptions,null,$maxHostConnections,$maxPendingPushes);
41+
}
42+
43+
static$curlVersion =null;
44+
$curlVersion =$curlVersion ??curl_version();
45+
46+
// HTTP/2 push crashes before curl 7.61
47+
if (0x073d00 >$curlVersion['version_number'] || !(CURL_VERSION_HTTP2 &$curlVersion['features'])) {
48+
returnnewAmpHttpClient($defaultOptions,null,$maxHostConnections,$maxPendingPushes);
49+
}
50+
}
51+
3252
if (\extension_loaded('curl')) {
3353
if ('\\' !== \DIRECTORY_SEPARATOR ||ini_get('curl.cainfo') ||ini_get('openssl.cafile') ||ini_get('openssl.capath')) {
3454
returnnewCurlHttpClient($defaultOptions,$maxHostConnections,$maxPendingPushes);
@@ -37,6 +57,10 @@ public static function create(array $defaultOptions = [], int $maxHostConnection
3757
@trigger_error('Configure the "curl.cainfo", "openssl.cafile" or "openssl.capath" php.ini setting to enable the CurlHttpClient',E_USER_WARNING);
3858
}
3959

60+
if ($amp) {
61+
returnnewAmpHttpClient($defaultOptions,null,$maxHostConnections,$maxPendingPushes);
62+
}
63+
4064
returnnewNativeHttpClient($defaultOptions,$maxHostConnections);
4165
}
4266

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,9 @@ public function connect(string $uri, ?ConnectContext $context = null, ?Cancellat
161161
};
162162
$connector->connector =newDnsConnector(newAmpResolver($this->dnsCache));
163163

164-
$context = (newConnectContext())->withTlsContext($context);
164+
$context = (newConnectContext())
165+
->withTcpNoDelay()
166+
->withTlsContext($context);
165167

166168
if ($options['bindto']) {
167169
if (file_exists($options['bindto'])) {

‎src/Symfony/Component/HttpClient/Tests/HttpClientTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@
1212
namespaceSymfony\Component\HttpClient\Tests;
1313

1414
usePHPUnit\Framework\TestCase;
15+
useSymfony\Component\HttpClient\AmpHttpClient;
1516
useSymfony\Component\HttpClient\CurlHttpClient;
1617
useSymfony\Component\HttpClient\HttpClient;
17-
useSymfony\Component\HttpClient\NativeHttpClient;
1818

1919
class HttpClientTestextends TestCase
2020
{
2121
publicfunctiontestCreateClient()
2222
{
23-
if (\extension_loaded('curl') && ('\\' !== \DIRECTORY_SEPARATOR ||ini_get('curl.cainfo') ||ini_get('openssl.cafile') ||ini_get('openssl.capath'))) {
23+
if (\extension_loaded('curl') && ('\\' !== \DIRECTORY_SEPARATOR ||ini_get('curl.cainfo') ||ini_get('openssl.cafile') ||ini_get('openssl.capath')) &&0x073d00 <=curl_version()['version_number']) {
2424
$this->assertInstanceOf(CurlHttpClient::class, HttpClient::create());
2525
}else {
26-
$this->assertInstanceOf(NativeHttpClient::class, HttpClient::create());
26+
$this->assertInstanceOf(AmpHttpClient::class, HttpClient::create());
2727
}
2828
}
2929
}

‎src/Symfony/Component/HttpClient/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"symfony/service-contracts":"^1.0|^2"
2929
},
3030
"require-dev": {
31-
"amphp/http-client":"^4.2",
31+
"amphp/http-client":"^4.2.1",
3232
"amphp/http-tunnel":"^1.0",
3333
"amphp/socket":"^1.1",
3434
"guzzlehttp/promises":"^1.3.1",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp