13
13
14
14
use Psr \Log \LoggerAwareInterface ;
15
15
use Psr \Log \LoggerAwareTrait ;
16
- use Psr \Log \LoggerInterface ;
17
16
use Symfony \Component \HttpClient \Exception \InvalidArgumentException ;
18
17
use Symfony \Component \HttpClient \Exception \TransportException ;
19
18
use Symfony \Component \HttpClient \Internal \CurlClientState ;
@@ -71,7 +70,7 @@ public function __construct(array $defaultOptions = [], int $maxHostConnections
71
70
[, $ this ->defaultOptions ] = self ::prepareRequest (null , null , $ defaultOptions , $ this ->defaultOptions );
72
71
}
73
72
74
- $ this ->multi = $ multi = new CurlClientState ();
73
+ $ this ->multi = new CurlClientState ();
75
74
self ::$ curlVersion = self ::$ curlVersion ?? curl_version ();
76
75
77
76
// 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
95
94
return ;
96
95
}
97
96
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 );
102
99
});
103
100
}
104
101
@@ -361,7 +358,7 @@ public function __destruct()
361
358
$ this ->reset ();
362
359
}
363
360
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
365
362
{
366
363
$ headers = [];
367
364
$ origin = curl_getinfo ($ parent , CURLINFO_EFFECTIVE_URL );
@@ -373,7 +370,7 @@ private static function handlePush($parent, $pushed, array $requestHeaders, Curl
373
370
}
374
371
375
372
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 ));
377
374
378
375
return CURL_PUSH_DENY ;
379
376
}
@@ -384,21 +381,21 @@ private static function handlePush($parent, $pushed, array $requestHeaders, Curl
384
381
// but this is a MUST in the HTTP/2 RFC; let's restrict pushes to the original host,
385
382
// ignoring domains mentioned as alt-name in the certificate for now (same as curl).
386
383
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 ));
388
385
389
386
return CURL_PUSH_DENY ;
390
387
}
391
388
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 ));
396
393
}
397
394
398
395
$ 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 ));
400
397
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 );
402
399
403
400
return CURL_PUSH_OK ;
404
401
}
0 commit comments