Index: branches/5.3.x/core/units/helpers/curl_helper.php =================================================================== diff -u -N -r15974 -r16111 --- branches/5.3.x/core/units/helpers/curl_helper.php (.../curl_helper.php) (revision 15974) +++ branches/5.3.x/core/units/helpers/curl_helper.php (.../curl_helper.php) (revision 16111) @@ -1,6 +1,6 @@ lastErrorCode = 0; + $this->lastErrorMsg = ''; + $this->lastHTTPCode = 0; + $this->lastRedirectCount = 0; + } + + /** * Sets CURL options (adds to options set before) * * @param Array $options_hash @@ -190,6 +203,7 @@ // hardcoded options CURLOPT_RETURNTRANSFER => 1, CURLOPT_REFERER => PROTOCOL.SERVER_NAME, + CURLOPT_MAXREDIRS => 5, // don't verify SSL certificates CURLOPT_SSL_VERIFYPEER => false, @@ -276,11 +290,13 @@ * Sets request method to be used in next request * * @param int $request_method + * + * @throws InvalidArgumentException When invalid request method given. */ public function SetRequestMethod($request_method) { - if ($request_method != self::REQUEST_METHOD_GET || $request_method != self::REQUEST_METHOD_POST) { - throw new Exception('Method "' . __METHOD__ . '": Invalid $request_method parameter value'); + if ($request_method != self::REQUEST_METHOD_GET && $request_method != self::REQUEST_METHOD_POST) { + throw new InvalidArgumentException('Method "' . __METHOD__ . '": Invalid $request_method parameter value'); } $this->requestMethod = $request_method; @@ -390,6 +406,7 @@ */ protected function _sendRequest() { + $this->resetLastInfo(); curl_setopt($this->connectionID, CURLOPT_RETURNTRANSFER, true); if ( $this->followLocation ) { @@ -425,6 +442,10 @@ $url = trim(array_pop($regs)); $url_parsed = parse_url($url); + if ( $this->lastRedirectCount == $this->options[CURLOPT_MAXREDIRS] ) { + return $this->setError(CURLE_TOO_MANY_REDIRECTS, 'Maximum (' . $this->options[CURLOPT_MAXREDIRS] . ') redirects followed'); + } + if ( isset($url_parsed) ) { curl_setopt($this->connectionID, CURLOPT_URL, $url); $this->lastRedirectCount++; @@ -439,6 +460,22 @@ } /** + * Sets error manually. + * + * @param integer $code Code. + * @param string $message Message. + * + * @return boolean + */ + protected function setError($code, $message) + { + $this->lastErrorCode = $code; + $this->lastErrorMsg = $message; + + return false; + } + + /** * Returns various info about request made * * @param int $info_type @@ -476,8 +513,12 @@ */ public function Finalize($close_connection = true) { - $this->lastErrorCode = curl_errno($this->connectionID); - $this->lastErrorMsg = curl_error($this->connectionID); + if ( $this->lastErrorCode == 0 ) { + // error not set manually -> get it from curl + $this->lastErrorCode = curl_errno($this->connectionID); + $this->lastErrorMsg = curl_error($this->connectionID); + } + $this->lastHTTPCode = $this->getInfo(CURLINFO_HTTP_CODE); if ( $close_connection ) { @@ -525,4 +566,4 @@ return ($this->lastHTTPCode == 200) || ($this->lastHTTPCode >= 300 && $this->lastHTTPCode < 310); } - } \ No newline at end of file + }