Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 30 additions & 8 deletions lib/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ class Client
*/
protected $savedRequests;

/**
* @var bool
*/
protected $verifySSLCerts;

/**
* @var bool
*/
Expand All @@ -217,20 +222,22 @@ class Client
/**
* Initialize the client
*
* @param string $host the base url (e.g. https://api.sendgrid.com)
* @param array $headers global request headers
* @param string $version api version (configurable) - this is specific to the SendGrid API
* @param array $path holds the segments of the url path
* @param array $curlOptions extra options to set during curl initialization
* @param bool $retryOnLimit set default retry on limit flag
* @param string $host the base url (e.g. https://api.sendgrid.com)
* @param array $headers global request headers
* @param string $version api version (configurable) - this is specific to the SendGrid API
* @param array $path holds the segments of the url path
* @param array $curlOptions extra options to set during curl initialization
* @param bool $verifySSLCerts set default verify certificates flag
* @param bool $retryOnLimit set default retry on limit flag
*/
public function __construct($host, $headers = null, $version = null, $path = null, $curlOptions = null, $retryOnLimit = false)
public function __construct($host, $headers = null, $version = null, $path = null, $curlOptions = null, $verifySSLCerts = true, $retryOnLimit = false)
{
$this->host = $host;
$this->headers = $headers ?: [];
$this->version = $version;
$this->path = $path ?: [];
$this->curlOptions = $curlOptions ?: [];
$this->verifySSLCerts = $verifySSLCerts;
$this->retryOnLimit = $retryOnLimit;
$this->isConcurrentRequest = false;
$this->savedRequests = [];
Expand Down Expand Up @@ -304,6 +311,20 @@ public function setRetryOnLimit($retry)
return $this;
}

/**
* Set default verify certificates flag
*
* @param bool $verifySSLCerts
*
* @return Client
*/
public function setVerifySSLCerts($verifySSLCerts)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It only has the setVerifySSLCerts method.

Do we need to add the getVerifySSLCerts method?

I think we have this method to get current $verifySSLCerts value.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine as-is. We don't have getters for the other options.

{
$this->verifySSLCerts = $verifySSLCerts;

return $this;
}

/**
* Set concurrent request flag
*
Expand Down Expand Up @@ -350,7 +371,7 @@ private function createCurlOptions($method, $body = null, $headers = null)
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => true,
CURLOPT_CUSTOMREQUEST => strtoupper($method),
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYPEER => $this->verifySSLCerts,
CURLOPT_FAILONERROR => false
] + $this->curlOptions;

Expand Down Expand Up @@ -545,6 +566,7 @@ public function _($name = null)
}
$client = new static($this->host, $this->headers, $this->version, $this->path);
$client->setCurlOptions($this->curlOptions);
$client->setVerifySSLCerts($this->verifySSLCerts);
$client->setRetryOnLimit($this->retryOnLimit);
$this->path = [];

Expand Down