diff --git a/lib/internal/Magento/Framework/HTTP/Client/Curl.php b/lib/internal/Magento/Framework/HTTP/Client/Curl.php index 67525f62f6336cf7de844e866a153be223dc0b5c..136f9924933512b5e64f83e27b6b825e8a2590ca 100644 --- a/lib/internal/Magento/Framework/HTTP/Client/Curl.php +++ b/lib/internal/Magento/Framework/HTTP/Client/Curl.php @@ -9,14 +9,17 @@ namespace Magento\Framework\HTTP\Client; * Class to work with HTTP protocol using curl library * * @author Magento Core Team <core@magentocommerce.com> + * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) */ class Curl implements \Magento\Framework\HTTP\ClientInterface { + const SSL_VERSION = 6; + /** * Max supported protocol by curl CURL_SSLVERSION_TLSv1_2 * @var int */ - private static $sslVersion = 6; + private $sslVersion; /** * Hostname @@ -86,7 +89,7 @@ class Curl implements \Magento\Framework\HTTP\ClientInterface /** * Curl - * @var object + * @var resource */ protected $_ch; @@ -117,10 +120,11 @@ class Curl implements \Magento\Framework\HTTP\ClientInterface } /** - * Constructor + * @param int|null $sslVersion */ - public function __construct() + public function __construct($sslVersion = null) { + $this->sslVersion = $sslVersion; } /** @@ -377,10 +381,9 @@ class Curl implements \Magento\Framework\HTTP\ClientInterface $this->curlOption(CURLOPT_PORT, $this->_port); } - //$this->curlOption(CURLOPT_HEADER, 1); $this->curlOption(CURLOPT_RETURNTRANSFER, 1); $this->curlOption(CURLOPT_HEADERFUNCTION, [$this, 'parseHeaders']); - $this->curlOption(CURLOPT_SSLVERSION, self::$sslVersion); + $this->setSSLVersion($this->sslVersion); if (count($this->_curlUserOptions)) { foreach ($this->_curlUserOptions as $k => $v) { @@ -415,6 +418,7 @@ class Curl implements \Magento\Framework\HTTP\ClientInterface * @param resource $ch curl handle, not needed * @param string $data * @return int + * @throws \Exception * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ protected function parseHeaders($ch, $data) @@ -422,11 +426,10 @@ class Curl implements \Magento\Framework\HTTP\ClientInterface if ($this->_headerCount == 0) { $line = explode(" ", trim($data), 3); if (count($line) != 3) { - return $this->doError("Invalid response line returned from server: " . $data); + $this->doError("Invalid response line returned from server: " . $data); } $this->_responseStatus = intval($line[1]); } else { - //var_dump($data); $name = $value = ''; $out = explode(": ", trim($data), 2); if (count($out) == 2) { @@ -493,4 +496,19 @@ class Curl implements \Magento\Framework\HTTP\ClientInterface { $this->_curlUserOptions[$name] = $value; } + + /** + * Set ssl version to specified version or default + * + * @param int $sslVersion + * @return void + */ + private function setSSLVersion($sslVersion) + { + if ($sslVersion) { + $this->sslVersion = $sslVersion; + } else { + $this->sslVersion = self::SSL_VERSION; + } + } }