@@ -116,23 +116,6 @@ public function request(string $method, string $url, array $options = []): Respo
116
116
$ options ['normalized_headers ' ]['user-agent ' ][] = $ options ['headers ' ][] = 'User-Agent: Symfony HttpClient/Curl ' ;
117
117
}
118
118
119
- if ($ pushedResponse = $ this ->multi ->pushedResponses [$ url ] ?? null ) {
120
- unset($ this ->multi ->pushedResponses [$ url ]);
121
-
122
- if (self ::acceptPushForRequest ($ method , $ options , $ pushedResponse )) {
123
- $ this ->logger && $ this ->logger ->debug (sprintf ('Accepting pushed response: "%s %s" ' , $ method , $ url ));
124
-
125
- // Reinitialize the pushed response with request's options
126
- $ pushedResponse ->response ->__construct ($ this ->multi , $ url , $ options , $ this ->logger );
127
-
128
- return $ pushedResponse ->response ;
129
- }
130
-
131
- $ this ->logger && $ this ->logger ->debug (sprintf ('Rejecting pushed response: "%s". ' , $ url ));
132
- }
133
-
134
- $ this ->logger && $ this ->logger ->info (sprintf ('Request: "%s %s" ' , $ method , $ url ));
135
-
136
119
$ curlopts = [
137
120
CURLOPT_URL => $ url ,
138
121
CURLOPT_TCP_NODELAY => true ,
@@ -267,7 +250,26 @@ public function request(string $method, string $url, array $options = []): Respo
267
250
$ curlopts [file_exists ($ options ['bindto ' ]) ? CURLOPT_UNIX_SOCKET_PATH : CURLOPT_INTERFACE ] = $ options ['bindto ' ];
268
251
}
269
252
270
- $ ch = curl_init ();
253
+ if ($ pushedResponse = $ this ->multi ->pushedResponses [$ url ] ?? null ) {
254
+ unset($ this ->multi ->pushedResponses [$ url ]);
255
+
256
+ if (self ::acceptPushForRequest ($ method , $ options , $ pushedResponse )) {
257
+ $ this ->logger && $ this ->logger ->debug (sprintf ('Accepting pushed response: "%s %s" ' , $ method , $ url ));
258
+
259
+ // Reinitialize the pushed response with request's options
260
+ $ ch = $ pushedResponse ->handle ;
261
+ $ pushedResponse = $ pushedResponse ->response ;
262
+ $ pushedResponse ->__construct ($ this ->multi , $ url , $ options , $ this ->logger );
263
+ } else {
264
+ $ this ->logger && $ this ->logger ->debug (sprintf ('Rejecting pushed response: "%s". ' , $ url ));
265
+ $ pushedResponse = null ;
266
+ }
267
+ }
268
+
269
+ if (!$ pushedResponse ) {
270
+ $ ch = curl_init ();
271
+ $ this ->logger && $ this ->logger ->info (sprintf ('Request: "%s %s" ' , $ method , $ url ));
272
+ }
271
273
272
274
foreach ($ curlopts as $ opt => $ value ) {
273
275
if (null !== $ value && !curl_setopt ($ ch , $ opt , $ value ) && CURLOPT_CERTINFO !== $ opt ) {
@@ -279,7 +281,7 @@ public function request(string $method, string $url, array $options = []): Respo
279
281
}
280
282
}
281
283
282
- return new CurlResponse ($ this ->multi , $ ch , $ options , $ this ->logger , $ method , self ::createRedirectResolver ($ options , $ host ));
284
+ return $ pushedResponse ?? new CurlResponse ($ this ->multi , $ ch , $ options , $ this ->logger , $ method , self ::createRedirectResolver ($ options , $ host ));
283
285
}
284
286
285
287
/**
@@ -369,7 +371,7 @@ private static function handlePush($parent, $pushed, array $requestHeaders, Curl
369
371
$ url .= $ headers [':path ' ][0 ];
370
372
$ logger && $ logger ->debug (sprintf ('Queueing pushed response: "%s" ' , $ url ));
371
373
372
- $ multi ->pushedResponses [$ url ] = new PushedResponse (new CurlResponse ($ multi , $ pushed ), $ headers , $ multi ->openHandles [(int ) $ parent ][1 ] ?? []);
374
+ $ multi ->pushedResponses [$ url ] = new PushedResponse (new CurlResponse ($ multi , $ pushed ), $ headers , $ multi ->openHandles [(int ) $ parent ][1 ] ?? [], $ pushed );
373
375
374
376
return CURL_PUSH_OK ;
375
377
}
0 commit comments