Skip to content

Commit a19c4df

Browse files
Merge pull request #17 from codelathe/fix/handle_responses_with_100_and_redirects
Fix debug mode for redirects
2 parents 5f5cead + 77c6202 commit a19c4df

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

fccloudapi.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2623,7 +2623,21 @@ protected function afterRequestDebug(string $method, string $url, string $postDa
26232623
$this->debugMessages['Response Code'] = curl_getinfo($this->curl_handle, CURLINFO_HTTP_CODE);
26242624

26252625
// Response Headers and body
2626-
[$rawHeaders, $body] = explode("\n\n", $result, 2);
2626+
2627+
// removing 100 and redirect responses
2628+
$regex = '/^HTTP\/[0-9.]+ [13][0-9]{2} [A-Z][a-z]+/';
2629+
while (preg_match($regex, $result)) {
2630+
$result = preg_replace($regex, '', $result);
2631+
$result = trim($result);
2632+
}
2633+
2634+
// splitting headers and body
2635+
if (strpos($result, "\n\n") === false) { // requests with no body
2636+
$rawHeaders = $result;
2637+
$body = '';
2638+
} else {
2639+
[$rawHeaders, $body] = explode("\n\n", $result, 2);
2640+
}
26272641
$lines = explode("\n", trim($rawHeaders));
26282642
array_shift($lines);
26292643
$headers = [];

0 commit comments

Comments
 (0)