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 5fb13bf

Browse filesBrowse files
bug #37319 [HttpClient] Convert CurlHttpClient::handlePush() to instance method (mpesari)
This PR was merged into the 4.4 branch. Discussion ---------- [HttpClient] Convert CurlHttpClient::handlePush() to instance method | Q | A | ------------- | --- | Branch? | 4.4 / 5.1 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #37252 <!-- prefix each issue number with "Fix #", if any --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> <!-- Replace this notice by a short README for your feature/bugfix. This will help people understand your PR and can be used as a start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - Never break backward compatibility (see https://symfony.com/bc). - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too.) - Features and deprecations must be submitted against branch master. --> Commits ------- 9497972 [HttpClient] Convert CurlHttpClient::handlePush() to instance method
2 parents 943c630 + 9497972 commit 5fb13bf
Copy full SHA for 5fb13bf

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.