@@ -385,27 +385,8 @@ public function send(string $method, string $url)
385
385
// Set the string we want to break our response from
386
386
$ breakString = "\r\n\r\n" ;
387
387
388
- // Strip out multiple redirect header sections
389
388
if (isset ($ this ->config ['allow_redirects ' ]) && $ this ->config ['allow_redirects ' ] !== false ) {
390
- while (preg_match ('/^HTTP\/\d(?:\.\d)? 3\d\d/ ' , $ output )) {
391
- $ breakStringPos = strpos ($ output , $ breakString );
392
- $ redirectHeaderSection = substr ($ output , 0 , $ breakStringPos );
393
- $ redirectHeaders = explode ("\n" , $ redirectHeaderSection );
394
- $ locationHeaderFound = false ;
395
-
396
- foreach ($ redirectHeaders as $ header ) {
397
- if (str_starts_with (strtolower ($ header ), 'location: ' )) {
398
- $ locationHeaderFound = true ;
399
- break ;
400
- }
401
- }
402
-
403
- if ($ locationHeaderFound ) {
404
- $ output = substr ($ output , $ breakStringPos + 4 );
405
- } else {
406
- break ;
407
- }
408
- }
389
+ $ output = $ this ->handleRedirectHeaders ($ output , $ breakString );
409
390
}
410
391
411
392
while (str_starts_with ($ output , 'HTTP/1.1 100 Continue ' )) {
@@ -736,4 +717,30 @@ protected function sendRequest(array $curlOptions = []): string
736
717
737
718
return $ output ;
738
719
}
720
+
721
+ private function handleRedirectHeaders (string $ output , string $ breakString ): string
722
+ {
723
+ // Strip out multiple redirect header sections
724
+ while (preg_match ('/^HTTP\/\d(?:\.\d)? 3\d\d/ ' , $ output )) {
725
+ $ breakStringPos = strpos ($ output , $ breakString );
726
+ $ redirectHeaderSection = substr ($ output , 0 , $ breakStringPos );
727
+ $ redirectHeaders = explode ("\n" , $ redirectHeaderSection );
728
+ $ locationHeaderFound = false ;
729
+
730
+ foreach ($ redirectHeaders as $ header ) {
731
+ if (str_starts_with (strtolower ($ header ), 'location: ' )) {
732
+ $ locationHeaderFound = true ;
733
+ break ;
734
+ }
735
+ }
736
+
737
+ if ($ locationHeaderFound ) {
738
+ $ output = substr ($ output , $ breakStringPos + 4 );
739
+ } else {
740
+ break ;
741
+ }
742
+ }
743
+
744
+ return $ output ;
745
+ }
739
746
}
0 commit comments