@@ -289,7 +289,19 @@ private static function parseHeaderLine($ch, string $data, array &$info, array &
289
289
// Regular header line: add it to the list
290
290
self ::addResponseHeaders ([substr ($ data , 0 , -2 )], $ info , $ headers );
291
291
292
- if (0 === strpos ($ data , 'HTTP ' ) && 300 <= $ info ['http_code ' ] && $ info ['http_code ' ] < 400 ) {
292
+ if (0 !== strpos ($ data , 'HTTP/ ' )) {
293
+ if (0 === stripos ($ data , 'Location: ' )) {
294
+ $ location = trim (substr ($ data , 9 , -2 ));
295
+ }
296
+
297
+ return \strlen ($ data );
298
+ }
299
+
300
+ if (\function_exists ('openssl_x509_read ' ) && $ certinfo = curl_getinfo ($ ch , CURLINFO_CERTINFO )) {
301
+ $ info ['peer_certificate_chain ' ] = array_map ('openssl_x509_read ' , array_column ($ certinfo , 'Cert ' ));
302
+ }
303
+
304
+ if (300 <= $ info ['http_code ' ] && $ info ['http_code ' ] < 400 ) {
293
305
if (curl_getinfo ($ ch , CURLINFO_REDIRECT_COUNT ) === $ options ['max_redirects ' ]) {
294
306
curl_setopt ($ ch , CURLOPT_FOLLOWLOCATION , false );
295
307
} elseif (303 === $ info ['http_code ' ] || ('POST ' === $ info ['http_method ' ] && \in_array ($ info ['http_code ' ], [301 , 302 ], true ))) {
@@ -298,15 +310,14 @@ private static function parseHeaderLine($ch, string $data, array &$info, array &
298
310
}
299
311
}
300
312
301
- if (0 === stripos ($ data , 'Location: ' )) {
302
- $ location = trim (substr ($ data , 9 , -2 ));
303
- }
304
-
305
313
return \strlen ($ data );
306
314
}
307
315
308
316
// End of headers: handle redirects and add to the activity list
309
- $ statusCode = curl_getinfo ($ ch , CURLINFO_RESPONSE_CODE );
317
+ if (200 > $ statusCode = curl_getinfo ($ ch , CURLINFO_RESPONSE_CODE )) {
318
+ return \strlen ($ data );
319
+ }
320
+
310
321
$ info ['redirect_url ' ] = null ;
311
322
312
323
if (300 <= $ statusCode && $ statusCode < 400 && null !== $ location ) {
@@ -336,10 +347,6 @@ private static function parseHeaderLine($ch, string $data, array &$info, array &
336
347
return 0 ;
337
348
}
338
349
339
- if (\function_exists ('openssl_x509_read ' ) && $ certinfo = curl_getinfo ($ ch , CURLINFO_CERTINFO )) {
340
- $ info ['peer_certificate_chain ' ] = array_map ('openssl_x509_read ' , array_column ($ certinfo , 'Cert ' ));
341
- }
342
-
343
350
curl_setopt ($ ch , CURLOPT_PRIVATE , 'content ' );
344
351
} elseif (null !== $ info ['redirect_url ' ] && $ logger ) {
345
352
$ logger ->info (sprintf ('Redirecting: "%s %s" ' , $ info ['http_code ' ], $ info ['redirect_url ' ]));
0 commit comments