1313
1414use Psr \Log \LoggerAwareInterface ;
1515use Psr \Log \LoggerAwareTrait ;
16- use Psr \Log \LoggerInterface ;
1716use Symfony \Component \HttpClient \Exception \InvalidArgumentException ;
1817use Symfony \Component \HttpClient \Exception \TransportException ;
1918use 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