1616use Symfony \Component \HttpClient \Exception \InvalidArgumentException ;
1717use Symfony \Component \HttpClient \Exception \TransportException ;
1818use Symfony \Component \HttpClient \Internal \CurlClientState ;
19- use Symfony \Component \HttpClient \Internal \PushedResponse ;
2019use Symfony \Component \HttpClient \Response \CurlResponse ;
2120use Symfony \Component \HttpClient \Response \ResponseStream ;
2221use Symfony \Contracts \HttpClient \HttpClientInterface ;
2726/**
2827 * A performant implementation of the HttpClientInterface contracts based on the curl extension.
2928 *
30- * This provides fully concurrent HTTP requests, with transparent
31- * HTTP/2 push when a curl version that supports it is installed.
29+ * This provides fully concurrent HTTP requests and support for HTTP/2.
3230 *
3331 * @author Nicolas Grekas <p@tchwork.com>
3432 */
@@ -52,7 +50,6 @@ final class CurlHttpClient implements HttpClientInterface, LoggerAwareInterface,
5250 private ?LoggerInterface $ logger = null ;
5351
5452 private int $ maxHostConnections ;
55- private int $ maxPendingPushes ;
5653
5754 /**
5855 * An internal object to share state between the client and its responses.
@@ -62,19 +59,16 @@ final class CurlHttpClient implements HttpClientInterface, LoggerAwareInterface,
6259 /**
6360 * @param array $defaultOptions Default request's options
6461 * @param int $maxHostConnections The maximum number of connections to a single host
65- * @param int $maxPendingPushes The maximum number of pushed responses to accept in the queue
6662 *
6763 * @see HttpClientInterface::OPTIONS_DEFAULTS for available options
6864 */
69- public function __construct (array $ defaultOptions = [], int $ maxHostConnections = 6 , int $ maxPendingPushes = 0 )
65+ public function __construct (array $ defaultOptions = [], int $ maxHostConnections = 6 )
7066 {
7167 if (!\extension_loaded ('curl ' )) {
7268 throw new \LogicException ('You cannot use the "Symfony\Component\HttpClient\CurlHttpClient" as the "curl" extension is not installed. ' );
7369 }
7470
7571 $ this ->maxHostConnections = $ maxHostConnections ;
76- $ this ->maxPendingPushes = $ maxPendingPushes ;
77-
7872 $ this ->defaultOptions ['buffer ' ] ??= self ::shouldBuffer (...);
7973
8074 if ($ defaultOptions ) {
@@ -299,27 +293,9 @@ public function request(string $method, string $url, array $options = []): Respo
299293 $ curlopts += $ options ['extra ' ]['curl ' ];
300294 }
301295
302- if ($ pushedResponse = $ multi ->pushedResponses [$ url ] ?? null ) {
303- unset($ multi ->pushedResponses [$ url ]);
304-
305- if (self ::acceptPushForRequest ($ method , $ options , $ pushedResponse )) {
306- $ this ->logger ?->debug(\sprintf ('Accepting pushed response: "%s %s" ' , $ method , $ url ));
307-
308- // Reinitialize the pushed response with request's options
309- $ ch = $ pushedResponse ->handle ;
310- $ pushedResponse = $ pushedResponse ->response ;
311- $ pushedResponse ->__construct ($ multi , $ url , $ options , $ this ->logger );
312- } else {
313- $ this ->logger ?->debug(\sprintf ('Rejecting pushed response: "%s" ' , $ url ));
314- $ pushedResponse = null ;
315- }
316- }
317-
318- if (!$ pushedResponse ) {
319- $ ch = curl_init ();
320- $ this ->logger ?->info(\sprintf ('Request: "%s %s" ' , $ method , $ url ));
321- $ curlopts += [\CURLOPT_SHARE => $ multi ->share ];
322- }
296+ $ ch = curl_init ();
297+ $ this ->logger ?->info(\sprintf ('Request: "%s %s" ' , $ method , $ url ));
298+ $ curlopts += [\CURLOPT_SHARE => $ multi ->share ];
323299
324300 foreach ($ curlopts as $ opt => $ value ) {
325301 if (\PHP_INT_SIZE === 8 && \defined ('CURLOPT_INFILESIZE_LARGE ' ) && \CURLOPT_INFILESIZE === $ opt && $ value >= 1 << 31 ) {
@@ -331,7 +307,7 @@ public function request(string $method, string $url, array $options = []): Respo
331307 }
332308 }
333309
334- return $ pushedResponse ?? new CurlResponse ($ multi , $ ch , $ options , $ this ->logger , $ method , self ::createRedirectResolver ($ options , $ authority ), CurlClientState::$ curlVersion ['version_number ' ], $ url );
310+ return new CurlResponse ($ multi , $ ch , $ options , $ this ->logger , $ method , self ::createRedirectResolver ($ options , $ authority ), CurlClientState::$ curlVersion ['version_number ' ], $ url );
335311 }
336312
337313 public function stream (ResponseInterface |iterable $ responses , ?float $ timeout = null ): ResponseStreamInterface
@@ -358,35 +334,6 @@ public function reset(): void
358334 }
359335 }
360336
361- /**
362- * Accepts pushed responses only if their headers related to authentication match the request.
363- */
364- private static function acceptPushForRequest (string $ method , array $ options , PushedResponse $ pushedResponse ): bool
365- {
366- if ('' !== $ options ['body ' ] || $ method !== $ pushedResponse ->requestHeaders [':method ' ][0 ]) {
367- return false ;
368- }
369-
370- foreach (['proxy ' , 'no_proxy ' , 'bindto ' , 'local_cert ' , 'local_pk ' ] as $ k ) {
371- if ($ options [$ k ] !== $ pushedResponse ->parentOptions [$ k ]) {
372- return false ;
373- }
374- }
375-
376- foreach (['authorization ' , 'cookie ' , 'range ' , 'proxy-authorization ' ] as $ k ) {
377- $ normalizedHeaders = $ options ['normalized_headers ' ][$ k ] ?? [];
378- foreach ($ normalizedHeaders as $ i => $ v ) {
379- $ normalizedHeaders [$ i ] = substr ($ v , \strlen ($ k ) + 2 );
380- }
381-
382- if (($ pushedResponse ->requestHeaders [$ k ] ?? []) !== $ normalizedHeaders ) {
383- return false ;
384- }
385- }
386-
387- return true ;
388- }
389-
390337 /**
391338 * Wraps the request's body callback to allow it to return strings longer than curl requested.
392339 */
@@ -455,7 +402,7 @@ private static function createRedirectResolver(array $options, string $authority
455402 private function ensureState (): CurlClientState
456403 {
457404 if (!isset ($ this ->multi )) {
458- $ this ->multi = new CurlClientState ($ this ->maxHostConnections , $ this -> maxPendingPushes );
405+ $ this ->multi = new CurlClientState ($ this ->maxHostConnections );
459406 $ this ->multi ->logger = $ this ->logger ;
460407 }
461408
0 commit comments