Skip to content

Commit

Permalink
Merge pull request #17 from codelathe/fix/handle_responses_with_100_a…
Browse files Browse the repository at this point in the history
…nd_redirects

Fix debug mode for redirects
  • Loading branch information
jefersonralmeida authored May 10, 2019
2 parents 5f5cead + 77c6202 commit a19c4df
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion fccloudapi.php
Original file line number Diff line number Diff line change
Expand Up @@ -2623,7 +2623,21 @@ protected function afterRequestDebug(string $method, string $url, string $postDa
$this->debugMessages['Response Code'] = curl_getinfo($this->curl_handle, CURLINFO_HTTP_CODE);

// Response Headers and body
[$rawHeaders, $body] = explode("\n\n", $result, 2);

// removing 100 and redirect responses
$regex = '/^HTTP\/[0-9.]+ [13][0-9]{2} [A-Z][a-z]+/';
while (preg_match($regex, $result)) {
$result = preg_replace($regex, '', $result);
$result = trim($result);
}

// splitting headers and body
if (strpos($result, "\n\n") === false) { // requests with no body
$rawHeaders = $result;
$body = '';
} else {
[$rawHeaders, $body] = explode("\n\n", $result, 2);
}
$lines = explode("\n", trim($rawHeaders));
array_shift($lines);
$headers = [];
Expand Down

0 comments on commit a19c4df

Please sign in to comment.