Skip to content

Commit 23354d4

Browse files
committed
fix: strip out multiple header sections for redirect
1 parent d968608 commit 23354d4

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

system/HTTP/CURLRequest.php

+23
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)