File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -385,6 +385,29 @@ public function send(string $method, string $url)
385385 // Set the string we want to break our response from
386386 $ breakString = "\r\n\r\n" ;
387387
388+ // Strip out multiple redirect header sections
389+ 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+ }
409+ }
410+
388411 while (str_starts_with ($ output , 'HTTP/1.1 100 Continue ' )) {
389412 $ output = substr ($ output , strpos ($ output , $ breakString ) + 4 );
390413 }
You can’t perform that action at this time.
0 commit comments