From 0e19a1aeecb19c0ce34b38af23e9eb4dd0a3c5ce Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Tue, 12 Jan 2010 12:26:42 +0100 Subject: [PATCH] Take into account that curl returns multiple headers in the response, if the actions required multiple requests. Take HTTP response code from curlinfo. --- framework/Http/lib/Horde/Http/Response/Curl.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/framework/Http/lib/Horde/Http/Response/Curl.php b/framework/Http/lib/Horde/Http/Response/Curl.php index 050ab0ef1..c513cc051 100644 --- a/framework/Http/lib/Horde/Http/Response/Curl.php +++ b/framework/Http/lib/Horde/Http/Response/Curl.php @@ -40,8 +40,8 @@ class Horde_Http_Response_Curl extends Horde_Http_Response_Base public function __construct($uri, $curlresult, $curlinfo) { $this->uri = $uri; - $this->_parseInfo($curlinfo); $this->_parseResult($curlresult); + $this->_parseInfo($curlinfo); } /** @@ -61,8 +61,13 @@ class Horde_Http_Response_Curl extends Horde_Http_Response_Base */ protected function _parseResult($curlresult) { - $endOfHeaders = strpos($curlresult, "\r\n\r\n"); - $headers = substr($curlresult, 0, $endOfHeaders); + /* Curl returns multiple headers, if the last action required multiple + * requests, e.g. when doing Digest authentication. Only parse the + * headers of the latest response. */ + preg_match_all('/(^|\r\n\r\n)(HTTP\/)/', $curlresult, $matches, PREG_OFFSET_CAPTURE); + $startOfHeaders = $matches[2][count($matches[2]) - 1][1]; + $endOfHeaders = strpos($curlresult, "\r\n\r\n", $startOfHeaders); + $headers = substr($curlresult, $startOfHeaders, $endOfHeaders - $startOfHeaders); $this->_parseHeaders($headers); $this->_body = substr($curlresult, $endOfHeaders + 4); } @@ -75,6 +80,7 @@ class Horde_Http_Response_Curl extends Horde_Http_Response_Base protected function _parseInfo($curlinfo) { $this->uri = $curlinfo['url']; + $this->code = $curlinfo['http_code']; $this->_info = $curlinfo; } } -- 2.11.0