@@ -310,14 +310,19 @@ private static function parseHeaderLine($ch, string $data, array &$info, array &
310
310
$ info ['redirect_url ' ] = null ;
311
311
312
312
if (300 <= $ statusCode && $ statusCode < 400 && null !== $ location ) {
313
- $ info ['redirect_url ' ] = $ resolveRedirect ($ ch , $ location );
314
- $ url = parse_url ($ location ?? ': ' );
315
-
316
- if (isset ($ url ['host ' ]) && null !== $ ip = $ multi ->dnsCache ->hostnames [$ url ['host ' ] = strtolower ($ url ['host ' ])] ?? null ) {
317
- // Populate DNS cache for redirects if needed
318
- $ port = $ url ['port ' ] ?? ('http ' === ($ url ['scheme ' ] ?? parse_url (curl_getinfo ($ ch , CURLINFO_EFFECTIVE_URL ), PHP_URL_SCHEME )) ? 80 : 443 );
319
- curl_setopt ($ ch , CURLOPT_RESOLVE , ["{$ url ['host ' ]}: $ port: $ ip " ]);
320
- $ multi ->dnsCache ->removals ["- {$ url ['host ' ]}: $ port " ] = "- {$ url ['host ' ]}: $ port " ;
313
+ if (null === $ info ['redirect_url ' ] = $ resolveRedirect ($ ch , $ location )) {
314
+ $ options ['max_redirects ' ] = curl_getinfo ($ ch , CURLINFO_REDIRECT_COUNT );
315
+ curl_setopt ($ ch , CURLOPT_FOLLOWLOCATION , false );
316
+ curl_setopt ($ ch , CURLOPT_MAXREDIRS , $ options ['max_redirects ' ]);
317
+ } else {
318
+ $ url = parse_url ($ location ?? ': ' );
319
+
320
+ if (isset ($ url ['host ' ]) && null !== $ ip = $ multi ->dnsCache ->hostnames [$ url ['host ' ] = strtolower ($ url ['host ' ])] ?? null ) {
321
+ // Populate DNS cache for redirects if needed
322
+ $ port = $ url ['port ' ] ?? ('http ' === ($ url ['scheme ' ] ?? parse_url (curl_getinfo ($ ch , CURLINFO_EFFECTIVE_URL ), PHP_URL_SCHEME )) ? 80 : 443 );
323
+ curl_setopt ($ ch , CURLOPT_RESOLVE , ["{$ url ['host ' ]}: $ port: $ ip " ]);
324
+ $ multi ->dnsCache ->removals ["- {$ url ['host ' ]}: $ port " ] = "- {$ url ['host ' ]}: $ port " ;
325
+ }
321
326
}
322
327
}
323
328
0 commit comments