@@ -119,23 +119,6 @@ public function request(string $method, string $url, array $options = []): Respo
119
119
$ options ['normalized_headers ' ]['user-agent ' ][] = $ options ['headers ' ][] = 'User-Agent: Symfony HttpClient/Curl ' ;
120
120
}
121
121
122
- if ($ pushedResponse = $ this ->multi ->pushedResponses [$ url ] ?? null ) {
123
- unset($ this ->multi ->pushedResponses [$ url ]);
124
-
125
- if (self ::acceptPushForRequest ($ method , $ options , $ pushedResponse )) {
126
- $ this ->logger && $ this ->logger ->debug (sprintf ('Accepting pushed response: "%s %s" ' , $ method , $ url ));
127
-
128
- // Reinitialize the pushed response with request's options
129
- $ pushedResponse ->response ->__construct ($ this ->multi , $ url , $ options , $ this ->logger );
130
-
131
- return $ pushedResponse ->response ;
132
- }
133
-
134
- $ this ->logger && $ this ->logger ->debug (sprintf ('Rejecting pushed response: "%s". ' , $ url ));
135
- }
136
-
137
- $ this ->logger && $ this ->logger ->info (sprintf ('Request: "%s %s" ' , $ method , $ url ));
138
-
139
122
$ curlopts = [
140
123
CURLOPT_URL => $ url ,
141
124
CURLOPT_TCP_NODELAY => true ,
@@ -294,7 +277,26 @@ public function request(string $method, string $url, array $options = []): Respo
294
277
$ curlopts [CURLOPT_TIMEOUT_MS ] = 1000 * $ options ['max_duration ' ];
295
278
}
296
279
297
- $ ch = curl_init ();
280
+ if ($ pushedResponse = $ this ->multi ->pushedResponses [$ url ] ?? null ) {
281
+ unset($ this ->multi ->pushedResponses [$ url ]);
282
+
283
+ if (self ::acceptPushForRequest ($ method , $ options , $ pushedResponse )) {
284
+ $ this ->logger && $ this ->logger ->debug (sprintf ('Accepting pushed response: "%s %s" ' , $ method , $ url ));
285
+
286
+ // Reinitialize the pushed response with request's options
287
+ $ ch = $ pushedResponse ->handle ;
288
+ $ pushedResponse = $ pushedResponse ->response ;
289
+ $ pushedResponse ->__construct ($ this ->multi , $ url , $ options , $ this ->logger );
290
+ } else {
291
+ $ this ->logger && $ this ->logger ->debug (sprintf ('Rejecting pushed response: "%s". ' , $ url ));
292
+ $ pushedResponse = null ;
293
+ }
294
+ }
295
+
296
+ if (!$ pushedResponse ) {
297
+ $ ch = curl_init ();
298
+ $ this ->logger && $ this ->logger ->info (sprintf ('Request: "%s %s" ' , $ method , $ url ));
299
+ }
298
300
299
301
foreach ($ curlopts as $ opt => $ value ) {
300
302
if (null !== $ value && !curl_setopt ($ ch , $ opt , $ value ) && CURLOPT_CERTINFO !== $ opt ) {
@@ -306,7 +308,7 @@ public function request(string $method, string $url, array $options = []): Respo
306
308
}
307
309
}
308
310
309
- return new CurlResponse ($ this ->multi , $ ch , $ options , $ this ->logger , $ method , self ::createRedirectResolver ($ options , $ host ));
311
+ return $ pushedResponse ?? new CurlResponse ($ this ->multi , $ ch , $ options , $ this ->logger , $ method , self ::createRedirectResolver ($ options , $ host ));
310
312
}
311
313
312
314
/**
@@ -396,7 +398,7 @@ private static function handlePush($parent, $pushed, array $requestHeaders, Curl
396
398
$ url .= $ headers [':path ' ][0 ];
397
399
$ logger && $ logger ->debug (sprintf ('Queueing pushed response: "%s" ' , $ url ));
398
400
399
- $ multi ->pushedResponses [$ url ] = new PushedResponse (new CurlResponse ($ multi , $ pushed ), $ headers , $ multi ->openHandles [(int ) $ parent ][1 ] ?? []);
401
+ $ multi ->pushedResponses [$ url ] = new PushedResponse (new CurlResponse ($ multi , $ pushed ), $ headers , $ multi ->openHandles [(int ) $ parent ][1 ] ?? [], $ pushed );
400
402
401
403
return CURL_PUSH_OK ;
402
404
}
0 commit comments