Skip to content

Commit

Permalink
Allow the timeout to be specified by the end user
Browse files Browse the repository at this point in the history
  • Loading branch information
paragonie-security committed Sep 27, 2019
1 parent 9b0bbc5 commit 67c01d4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/Certainty.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ class Certainty

/**
* @param Fetch|null $fetch
* @param int $timeout
*
* @return Client
* @throws \SodiumException
*/
public static function getGuzzleClient(Fetch $fetch = null)
public static function getGuzzleClient(Fetch $fetch = null, $timeout = 5)
{
$options = ['verify' => true];
if (!\is_null($fetch)) {
Expand All @@ -36,7 +37,7 @@ public static function getGuzzleClient(Fetch $fetch = null)
// https://github.com/curl/curl/blob/6aa86c493bd77b70d1f5018e102bc3094290d588/include/curl/curl.h#L1927
$options['curl.options'][CURLOPT_SSLVERSION] = CURL_SSLVERSION_TLSv1_2 | (CURL_SSLVERSION_TLSv1 << 16);
}
$options['connect_timeout'] = 5;
$options['connect_timeout'] = (int) $timeout;

return new Client($options);
}
Expand Down
8 changes: 5 additions & 3 deletions src/RemoteFetch.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class RemoteFetch extends Fetch
* @param \DateInterval|string|null $timeout
* @param string $chronicleUrl
* @param string $chroniclePublicKey
* @param int $connectTimeout
*
* @throws CertaintyException
* @throws \SodiumException
Expand All @@ -56,16 +57,17 @@ public function __construct(
Client $http = null,
$timeout = null,
$chronicleUrl = '',
$chroniclePublicKey = ''
$chroniclePublicKey = '',
$connectTimeout = 5
) {
parent::__construct($dataDir);
$this->url = $url;

if (\is_null($http)) {
if (\file_exists($this->dataDirectory . '/ca-certs.json')) {
$http = Certainty::getGuzzleClient(new Fetch($this->dataDirectory));
$http = Certainty::getGuzzleClient(new Fetch($this->dataDirectory), $connectTimeout);
} else {
$http = Certainty::getGuzzleClient(new Fetch(__DIR__."/../data/"));
$http = Certainty::getGuzzleClient(new Fetch(__DIR__."/../data/"), $connectTimeout);
}
}
/** @var Client $http */
Expand Down

0 comments on commit 67c01d4

Please sign in to comment.