|
9 | 9 | * Class to work with HTTP protocol using curl library
|
10 | 10 | *
|
11 | 11 | * @author Magento Core Team <[email protected]>
|
| 12 | + * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) |
12 | 13 | */
|
13 | 14 | class Curl implements \Magento\Framework\HTTP\ClientInterface
|
14 | 15 | {
|
| 16 | + const SSL_VERSION = 6; |
| 17 | + |
15 | 18 | /**
|
16 | 19 | * Max supported protocol by curl CURL_SSLVERSION_TLSv1_2
|
17 | 20 | * @var int
|
18 | 21 | */
|
19 |
| - private static $sslVersion = 6; |
| 22 | + private $sslVersion; |
20 | 23 |
|
21 | 24 | /**
|
22 | 25 | * Hostname
|
@@ -86,7 +89,7 @@ class Curl implements \Magento\Framework\HTTP\ClientInterface
|
86 | 89 |
|
87 | 90 | /**
|
88 | 91 | * Curl
|
89 |
| - * @var object |
| 92 | + * @var resource |
90 | 93 | */
|
91 | 94 | protected $_ch;
|
92 | 95 |
|
@@ -117,10 +120,11 @@ public function setTimeout($value)
|
117 | 120 | }
|
118 | 121 |
|
119 | 122 | /**
|
120 |
| - * Constructor |
| 123 | + * @param int|null $sslVersion |
121 | 124 | */
|
122 |
| - public function __construct() |
| 125 | + public function __construct($sslVersion = null) |
123 | 126 | {
|
| 127 | + $this->sslVersion = $sslVersion; |
124 | 128 | }
|
125 | 129 |
|
126 | 130 | /**
|
@@ -377,10 +381,9 @@ protected function makeRequest($method, $uri, $params = [])
|
377 | 381 | $this->curlOption(CURLOPT_PORT, $this->_port);
|
378 | 382 | }
|
379 | 383 |
|
380 |
| - //$this->curlOption(CURLOPT_HEADER, 1); |
381 | 384 | $this->curlOption(CURLOPT_RETURNTRANSFER, 1);
|
382 | 385 | $this->curlOption(CURLOPT_HEADERFUNCTION, [$this, 'parseHeaders']);
|
383 |
| - $this->curlOption(CURLOPT_SSLVERSION, self::$sslVersion); |
| 386 | + $this->setSSLVersion($this->sslVersion); |
384 | 387 |
|
385 | 388 | if (count($this->_curlUserOptions)) {
|
386 | 389 | foreach ($this->_curlUserOptions as $k => $v) {
|
@@ -415,18 +418,18 @@ public function doError($string)
|
415 | 418 | * @param resource $ch curl handle, not needed
|
416 | 419 | * @param string $data
|
417 | 420 | * @return int
|
| 421 | + * @throws \Exception |
418 | 422 | * @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
419 | 423 | */
|
420 | 424 | protected function parseHeaders($ch, $data)
|
421 | 425 | {
|
422 | 426 | if ($this->_headerCount == 0) {
|
423 | 427 | $line = explode(" ", trim($data), 3);
|
424 | 428 | if (count($line) != 3) {
|
425 |
| - return $this->doError("Invalid response line returned from server: " . $data); |
| 429 | + $this->doError("Invalid response line returned from server: " . $data); |
426 | 430 | }
|
427 | 431 | $this->_responseStatus = intval($line[1]);
|
428 | 432 | } else {
|
429 |
| - //var_dump($data); |
430 | 433 | $name = $value = '';
|
431 | 434 | $out = explode(": ", trim($data), 2);
|
432 | 435 | if (count($out) == 2) {
|
@@ -493,4 +496,19 @@ public function setOption($name, $value)
|
493 | 496 | {
|
494 | 497 | $this->_curlUserOptions[$name] = $value;
|
495 | 498 | }
|
| 499 | + |
| 500 | + /** |
| 501 | + * Set ssl version to specified version or default |
| 502 | + * |
| 503 | + * @param int $sslVersion |
| 504 | + * @return void |
| 505 | + */ |
| 506 | + private function setSSLVersion($sslVersion) |
| 507 | + { |
| 508 | + if ($sslVersion) { |
| 509 | + $this->sslVersion = $sslVersion; |
| 510 | + } else { |
| 511 | + $this->sslVersion = self::SSL_VERSION; |
| 512 | + } |
| 513 | + } |
496 | 514 | }
|
0 commit comments