From 67c01d4adab534a45eab670396addfbbb41791e9 Mon Sep 17 00:00:00 2001 From: Paragon Initiative Enterprises Date: Fri, 27 Sep 2019 05:17:40 -0400 Subject: [PATCH] Allow the timeout to be specified by the end user --- src/Certainty.php | 5 +++-- src/RemoteFetch.php | 8 +++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Certainty.php b/src/Certainty.php index 3691b96..c203550 100644 --- a/src/Certainty.php +++ b/src/Certainty.php @@ -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)) { @@ -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); } diff --git a/src/RemoteFetch.php b/src/RemoteFetch.php index 17f9182..9cb9715 100644 --- a/src/RemoteFetch.php +++ b/src/RemoteFetch.php @@ -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 @@ -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 */