From 0b6c8ad09fa87a0ef0c78b004b52a26b393b7834 Mon Sep 17 00:00:00 2001 From: Chuck Hagenbuch Date: Mon, 14 Sep 2009 22:48:14 -0400 Subject: [PATCH] using streams with curl is broken in PHP 5.3.0 --- framework/Http/lib/Horde/Http/Request/Curl.php | 33 ++++++++++++++------------ 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/framework/Http/lib/Horde/Http/Request/Curl.php b/framework/Http/lib/Horde/Http/Request/Curl.php index 8c4469b8a..9658c3e09 100644 --- a/framework/Http/lib/Horde/Http/Request/Curl.php +++ b/framework/Http/lib/Horde/Http/Request/Curl.php @@ -16,11 +16,13 @@ */ class Horde_Http_Request_Curl extends Horde_Http_Request_Base { - public function __construct() + public function __construct($args = array()) { if (!extension_loaded('curl')) { throw new Horde_Http_Exception('The curl extension is not installed. See http://php.net/curl.installation'); } + + parent::__construct($args); } /** @@ -30,24 +32,25 @@ class Horde_Http_Request_Curl extends Horde_Http_Request_Base */ public function send() { - $body = tmpfile(); - $headers = tmpfile(); - $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $this->uri); - curl_setopt($curl, CURLOPT_FILE, $body); - curl_setopt($curl, CURLOPT_WRITEHEADER, $headers); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curl, CURLOPT_HEADER, true); - // If we don't set POSTFIELDS to a string, and the first value begins - // with @, it will be treated as a filename, and the proper POST data - // isn't passed. - curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($this->data)); + $data = $this->data; + if (is_array($data)) { + // If we don't set POSTFIELDS to a string, and the first value + // begins with @, it will be treated as a filename, and the proper + // POST data isn't passed. + $data = http_build_query($data); + } + curl_setopt($curl, CURLOPT_POSTFIELDS, $this->data); $result = curl_exec($curl); - - rewind($body); - rewind($headers); - - return new Horde_Http_Response_Curl($this->uri, $body, stream_get_contents($headers)); + if ($result === false) { + throw new Horde_Http_Exception(curl_error($curl), curl_errno($curl)); + } + $info = curl_getinfo($curl); + return new Horde_Http_Response_Curl($result, $info); } } -- 2.11.0