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

Appearance settings

Commit 9497972

Browse filesBrowse files
committed
[HttpClient] Convert CurlHttpClient::handlePush() to instance method
Fix #37252
1 parent 943c630 commit 9497972
Copy full SHA for 9497972

File tree

Expand file treeCollapse file tree

1 file changed

+12
-15
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+12
-15
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/CurlHttpClient.php
+12-15Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use Psr\Log\LoggerAwareInterface;
1515
use Psr\Log\LoggerAwareTrait;
16-
use Psr\Log\LoggerInterface;
1716
use Symfony\Component\HttpClient\Exception\InvalidArgumentException;
1817
use Symfony\Component\HttpClient\Exception\TransportException;
1918
use Symfony\Component\HttpClient\Internal\CurlClientState;
@@ -71,7 +70,7 @@ public function __construct(array $defaultOptions = [], int $maxHostConnections
7170
[, $this->defaultOptions] = self::prepareRequest(null, null, $defaultOptions, $this->defaultOptions);
7271
}
7372

74-
$this->multi = $multi = new CurlClientState();
73+
$this->multi = new CurlClientState();
7574
self::$curlVersion = self::$curlVersion ?? curl_version();
7675

7776
// Don't enable HTTP/1.1 pipelining: it forces responses to be sent in order
@@ -95,10 +94,8 @@ public function __construct(array $defaultOptions = [], int $maxHostConnections
9594
return;
9695
}
9796

98-
$logger = &$this->logger;
99-
100-
curl_multi_setopt($this->multi->handle, CURLMOPT_PUSHFUNCTION, static function ($parent, $pushed, array $requestHeaders) use ($multi, $maxPendingPushes, &$logger) {
101-
return self::handlePush($parent, $pushed, $requestHeaders, $multi, $maxPendingPushes, $logger);
97+
curl_multi_setopt($this->multi->handle, CURLMOPT_PUSHFUNCTION, function ($parent, $pushed, array $requestHeaders) use ($maxPendingPushes) {
98+
return $this->handlePush($parent, $pushed, $requestHeaders, $maxPendingPushes);
10299
});
103100
}
104101

@@ -361,7 +358,7 @@ public function __destruct()
361358
$this->reset();
362359
}
363360

364-
private static function handlePush($parent, $pushed, array $requestHeaders, CurlClientState $multi, int $maxPendingPushes, ?LoggerInterface $logger): int
361+
private function handlePush($parent, $pushed, array $requestHeaders, int $maxPendingPushes): int
365362
{
366363
$headers = [];
367364
$origin = curl_getinfo($parent, CURLINFO_EFFECTIVE_URL);
@@ -373,7 +370,7 @@ private static function handlePush($parent, $pushed, array $requestHeaders, Curl
373370
}
374371

375372
if (!isset($headers[':method']) || !isset($headers[':scheme']) || !isset($headers[':authority']) || !isset($headers[':path'])) {
376-
$logger && $logger->debug(sprintf('Rejecting pushed response from "%s": pushed headers are invalid', $origin));
373+
$this->logger && $this->logger->debug(sprintf('Rejecting pushed response from "%s": pushed headers are invalid', $origin));
377374

378375
return CURL_PUSH_DENY;
379376
}
@@ -384,21 +381,21 @@ private static function handlePush($parent, $pushed, array $requestHeaders, Curl
384381
// but this is a MUST in the HTTP/2 RFC; let's restrict pushes to the original host,
385382
// ignoring domains mentioned as alt-name in the certificate for now (same as curl).
386383
if (0 !== strpos($origin, $url.'/')) {
387-
$logger && $logger->debug(sprintf('Rejecting pushed response from "%s": server is not authoritative for "%s"', $origin, $url));
384+
$this->logger && $this->logger->debug(sprintf('Rejecting pushed response from "%s": server is not authoritative for "%s"', $origin, $url));
388385

389386
return CURL_PUSH_DENY;
390387
}
391388

392-
if ($maxPendingPushes <= \count($multi->pushedResponses)) {
393-
$fifoUrl = key($multi->pushedResponses);
394-
unset($multi->pushedResponses[$fifoUrl]);
395-
$logger && $logger->debug(sprintf('Evicting oldest pushed response: "%s"', $fifoUrl));
389+
if ($maxPendingPushes <= \count($this->multi->pushedResponses)) {
390+
$fifoUrl = key($this->multi->pushedResponses);
391+
unset($this->multi->pushedResponses[$fifoUrl]);
392+
$this->logger && $this->logger->debug(sprintf('Evicting oldest pushed response: "%s"', $fifoUrl));
396393
}
397394

398395
$url .= $headers[':path'][0];
399-
$logger && $logger->debug(sprintf('Queueing pushed response: "%s"', $url));
396+
$this->logger && $this->logger->debug(sprintf('Queueing pushed response: "%s"', $url));
400397

401-
$multi->pushedResponses[$url] = new PushedResponse(new CurlResponse($multi, $pushed), $headers, $multi->openHandles[(int) $parent][1] ?? [], $pushed);
398+
$this->multi->pushedResponses[$url] = new PushedResponse(new CurlResponse($this->multi, $pushed), $headers, $this->multi->openHandles[(int) $parent][1] ?? [], $pushed);
402399

403400
return CURL_PUSH_OK;
404401
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.