Index: branches/5.2.x/core/units/helpers/curl_helper.php =================================================================== diff -u -N -r15856 -r15939 --- branches/5.2.x/core/units/helpers/curl_helper.php (.../curl_helper.php) (revision 15856) +++ branches/5.2.x/core/units/helpers/curl_helper.php (.../curl_helper.php) (revision 15939) @@ -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, @@ -283,11 +297,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'); + throw new InvalidArgumentException('Method "' . __METHOD__ . '": Invalid $request_method parameter value'); return ; } @@ -399,6 +415,7 @@ */ protected function _sendRequest() { + $this->resetLastInfo(); curl_setopt($this->connectionID, CURLOPT_RETURNTRANSFER, true); if ( $this->followLocation ) { @@ -434,6 +451,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++; @@ -448,6 +469,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 @@ -485,8 +522,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 ) {