Skip to content

Commit

Permalink
Merge pull request #40 from animkaTT/master
Browse files Browse the repository at this point in the history
Horoshop: Проверка https
  • Loading branch information
gwinn authored Mar 21, 2018
2 parents 54c5c7c + d980402 commit e1936dd
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/SaaS/Service/Horoshop/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Request
const METHOD_DELETE = 'DELETE';

protected $url;
protected $onHttps = true;

/**
* Client constructor.
Expand Down Expand Up @@ -83,21 +84,21 @@ public function makeRequest($path, $method, array $parameters = array())
$url = $this->url . $path;
$url = str_replace('https://', 'http://', $url);

if (self::METHOD_GET === $method && count($parameters)) {
$url .= '?' . http_build_query($parameters, '', '&');
if ($this->onHttps === true) {
$url = str_replace('http://', 'https://', $url);
}

if (self::METHOD_PUT === $method) {
$url = str_replace('http://', 'https://', $url);
if (self::METHOD_GET === $method && count($parameters)) {
$url .= '?' . http_build_query($parameters, '', '&');
}

$curlHandler = curl_init();
curl_setopt($curlHandler, CURLOPT_URL, $url);
curl_setopt($curlHandler, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlHandler, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curlHandler, CURLOPT_FAILONERROR, false);
curl_setopt($curlHandler, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curlHandler, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curlHandler, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($curlHandler, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curlHandler, CURLOPT_TIMEOUT, 180);

if (self::METHOD_POST === $method) {
Expand All @@ -120,6 +121,13 @@ public function makeRequest($path, $method, array $parameters = array())
}

$responseBody = curl_exec($curlHandler);

if (curl_getinfo($curlHandler, CURLINFO_SSL_VERIFYRESULT) !== 0) {
$this->onHttps = false;

return $this->makeRequest($path, $method, $parameters);
}

$statusCode = curl_getinfo($curlHandler, CURLINFO_HTTP_CODE);
$errno = curl_errno($curlHandler);
$error = curl_error($curlHandler);
Expand Down

0 comments on commit e1936dd

Please sign in to comment.