From c90d5f0e6cbaf57712746f38a8f4cf7d837a18d7 Mon Sep 17 00:00:00 2001 From: Jeferson Almeida Date: Thu, 9 May 2019 14:59:57 -0300 Subject: [PATCH 1/2] * On debug mode, fixed the headers and body splitting when the response contains redirections or 100 responses. --- fccloudapi.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fccloudapi.php b/fccloudapi.php index 6de338f..f07db46 100644 --- a/fccloudapi.php +++ b/fccloudapi.php @@ -2623,6 +2623,15 @@ 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 + + // 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 [$rawHeaders, $body] = explode("\n\n", $result, 2); $lines = explode("\n", trim($rawHeaders)); array_shift($lines); From 77c62021fd5e40a14ce05edb8408a14fd7cd6fc3 Mon Sep 17 00:00:00 2001 From: Jeferson Almeida Date: Thu, 9 May 2019 15:19:09 -0300 Subject: [PATCH 2/2] * Handling requests with no body. --- fccloudapi.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fccloudapi.php b/fccloudapi.php index f07db46..f40c30e 100644 --- a/fccloudapi.php +++ b/fccloudapi.php @@ -2632,7 +2632,12 @@ protected function afterRequestDebug(string $method, string $url, string $postDa } // splitting headers and body - [$rawHeaders, $body] = explode("\n\n", $result, 2); + 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 = [];