Index: curl_helper.php =================================================================== --- curl_helper.php (revision 15359) +++ curl_helper.php (working copy) @@ -34,7 +34,7 @@ * @var resource * @access protected */ - protected $connectionID = null; + protected $connectionID = NULL; /** * Response waiting timeout in seconds @@ -333,7 +333,7 @@ * @return string * @access public */ - public function Send($url, $close_connection = true, $log_status = null, $log_message = '') + public function Send($url, $close_connection = true, $log_status = NULL, $log_message = '') { if ( isset($log_status) ) { // override debug mode setting @@ -378,7 +378,7 @@ $this->responseHeaders = Array (); $this->prepareOptions(); - $this->lastResponse = $this->execFollow(); + $this->lastResponse = $this->_sendRequest(); $this->Finalize($close_connection); @@ -386,23 +386,39 @@ } /** - * Fixes curl inability to automatically follow location when safe_mode/open_basedir restriction in effect + * Reads data from remote url * - * @param bool $headers_only * @return string * @access protected */ - protected function execFollow($headers_only = false) + protected function _sendRequest() { - curl_setopt($this->connectionID, CURLOPT_HEADER, true); curl_setopt($this->connectionID, CURLOPT_RETURNTRANSFER, true); - if ( $this->followLocation && !$this->followLocationLimited() ) { - // no restrictions - let curl do automatic redirects - curl_setopt($this->connectionID, CURLOPT_FOLLOWLOCATION, true); + if ( $this->followLocation ) { + if ( $this->followLocationLimited() ) { + return $this->_followLocationManually(); + } + else { + // no restrictions - let curl do automatic redirects + curl_setopt($this->connectionID, CURLOPT_FOLLOWLOCATION, true); + } } + return curl_exec($this->connectionID); + } + + /** + * Fixes curl inability to automatically follow location when safe_mode/open_basedir restriction in effect + * + * @return string + * @access protected + */ + protected function _followLocationManually() + { + curl_setopt($this->connectionID, CURLOPT_HEADER, true); $data = curl_exec($this->connectionID); + $http_code = $this->getInfo(CURLINFO_HTTP_CODE); if ( $http_code == 301 || $http_code == 302 ) { @@ -416,14 +432,10 @@ curl_setopt($this->connectionID, CURLOPT_URL, $url); $this->lastRedirectCount++; - return $this->execFollow($headers_only); + return $this->_followLocationManually(); } } - if ( $headers_only ) { - return $data; - } - list(, $body) = explode("\r\n\r\n", $data, 2); return $body;