diff --git a/libraries/src/Http/Transport/CurlTransport.php b/libraries/src/Http/Transport/CurlTransport.php index e4aac318e6ac5..89da49164a3c3 100644 --- a/libraries/src/Http/Transport/CurlTransport.php +++ b/libraries/src/Http/Transport/CurlTransport.php @@ -188,6 +188,14 @@ public function request($method, Uri $uri, $data = null, array $headers = null, foreach ($this->options->get('transport.curl', array()) as $key => $value) { $options[$key] = $value; + + if ($key == CURLOPT_FILE && (bool) $value) + { + $this->headers = ''; + + $options[CURLOPT_HEADER] = false; + $options[CURLOPT_HEADERFUNCTION] = array($this, 'getHeaders'); + } } // Authentification, if needed @@ -203,8 +211,8 @@ public function request($method, Uri $uri, $data = null, array $headers = null, // Execute the request and close the connection. $content = curl_exec($ch); - // Check if the content is a string. If it is not, it must be an error. - if (!is_string($content)) + // Check if the content is a string or is boolean true. If it is not, it must be an error. + if (!is_string($content) && !is_bool($content)) { $message = curl_error($ch); @@ -223,6 +231,12 @@ public function request($method, Uri $uri, $data = null, array $headers = null, // Close the connection. curl_close($ch); + // If headers are set append to the content. + if (isset($this->headers)) + { + $content = $this->headers . (is_bool($content) ? "" : $content); + } + $response = $this->getResponse($content, $info); // Manually follow redirects if server doesn't allow to follow location using curl @@ -367,4 +381,19 @@ private function redirectsAllowed() return false; } + + /** + * Gets each header returned by cURL, appending it to the headers string. + * + * @param resource $ch The cURL resource. + * @param string $header The header string. + * + * @return int The length of the header. + */ + private function getHeaders($ch, $header) + { + $this->headers .= $header; + + return strlen($header); + } }