10000 [HttpClient] Convert CurlHttpClient::handlePush() to instance method by mpesari · Pull Request #37319 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpClient] Convert CurlHttpClient::handlePush() to instance method #37319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions src/Symfony/Component/HttpClient/CurlHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpClient\Exception\InvalidArgumentException;
use Symfony\Component\HttpClient\Exception\TransportException;
use Symfony\Component\HttpClient\Internal\CurlClientState;
Expand Down Expand Up @@ -71,7 +70,7 @@ public function __construct(array $defaultOptions = [], int $maxHostConnections
[, $this->defaultOptions] = self::prepareRequest(null, null, $defaultOptions, $this->defaultOptions);
}

$this->multi = $multi = new CurlClientState();
$this->multi = new CurlClientState();
self::$curlVersion = self::$curlVersion ?? curl_version();

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

$logger = &$this->logger;

curl_multi_setopt($this->multi->handle, CURLMOPT_PUSHFUNCTION, static function ($parent, $pushed, array $requestHeaders) use ($multi, $maxPendingPushes, &$logger) {
return self::handlePush($parent, $pushed, $requestHeaders, $multi, $maxPendingPushes, $logger);
curl_multi_setopt($this->multi->handle, CURLMOPT_PUSHFUNCTION, function ($parent, $pushed, array $requestHeaders) use ($maxPendingPushes) {
return $this->handlePush($parent, $pushed, $requestHeaders, $maxPendingPushes);
});
}

Expand Down Expand Up @@ -361,7 +358,7 @@ public function __destruct()
$this->reset();
}

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

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

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

return CURL_PUSH_DENY;
}

if ($maxPendingPushes <= \count($multi->pushedResponses)) {
$fifoUrl = key($multi->pushedResponses);
unset($multi->pushedResponses[$fifoUrl]);
$logger && $logger->debug(sprintf('Evicting oldest pushed response: "%s"', $fifoUrl));
if ($maxPendingPushes <= \count($this->multi->pushedResponses)) {
$fifoUrl = key($this->multi->pushedResponses);
unset($this->multi->pushedResponses[$fifoUrl]);
$this->logger && $this->logger->debug(sprintf('Evicting oldest pushed response: "%s"', $fifoUrl));
}

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

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

return CURL_PUSH_OK;
}
Expand Down
0