diff options
author | Josh <josh.t.richards@gmail.com> | 2024-12-27 10:57:00 -0500 |
---|---|---|
committer | Josh Richards <josh.t.richards@gmail.com> | 2025-01-07 16:49:28 -0500 |
commit | 35cb5d84caf5fb2a9e9d28f53b9f3f97805c0dc3 (patch) | |
tree | 3ff1f59ec91b5b3d5acf8fa85bfeb867a8ed7188 | |
parent | d5b6ce43a94837c7059a7918f73bd27495051023 (diff) | |
download | nextcloud-server-jtr-perf-checks-connectivity-https-proto.tar.gz nextcloud-server-jtr-perf-checks-connectivity-https-proto.zip |
perf(settings): Speed up InternetConnectivity setup checkjtr-perf-checks-connectivity-https-proto
Specify default protocol (https://) rather than let default handling test both http:// and https://
Signed-off-by: Josh <josh.t.richards@gmail.com>
-rw-r--r-- | apps/settings/lib/SetupChecks/InternetConnectivity.php | 20 | ||||
-rw-r--r-- | config/config.sample.php | 16 |
2 files changed, 18 insertions, 18 deletions
diff --git a/apps/settings/lib/SetupChecks/InternetConnectivity.php b/apps/settings/lib/SetupChecks/InternetConnectivity.php index 3a0af06e71b..18f2af63b8d 100644 --- a/apps/settings/lib/SetupChecks/InternetConnectivity.php +++ b/apps/settings/lib/SetupChecks/InternetConnectivity.php @@ -41,11 +41,12 @@ class InternetConnectivity implements ISetupCheck { } $siteArray = $this->config->getSystemValue('connectivity_check_domains', [ - 'www.nextcloud.com', 'www.startpage.com', 'www.eff.org', 'www.edri.org' + 'https://www.nextcloud.com', 'https://www.startpage.com', 'https://www.eff.org', 'https://www.edri.org' ]); foreach ($siteArray as $site) { if ($this->isSiteReachable($site)) { + // successful as soon as one connection succeeds return SetupResult::success(); } } @@ -55,19 +56,18 @@ class InternetConnectivity implements ISetupCheck { /** * Checks if the Nextcloud server can connect to a specific URL * @param string $site site domain or full URL with http/https protocol + * @return bool success/failure */ private function isSiteReachable(string $site): bool { + // if there is no protocol specified, test http:// first then, if necessary, https:// + if (preg_match('/^https?:\/\//', $site) !== 1) { + $httpSite = 'http://' . $site . '/'; + $httpsSite = 'https://' . $site . '/'; + return $this->isSiteReachable($httpSite) || $this->isSiteReachable($httpsSite); + } try { $client = $this->clientService->newClient(); - // if there is no protocol, test http:// AND https:// - if (preg_match('/^https?:\/\//', $site) !== 1) { - $httpSite = 'http://' . $site . '/'; - $client->get($httpSite); - $httpsSite = 'https://' . $site . '/'; - $client->get($httpsSite); - } else { - $client->get($site); - } + $client->get($site); } catch (\Exception $e) { $this->logger->error('Cannot connect to: ' . $site, [ 'app' => 'internet_connection_check', diff --git a/config/config.sample.php b/config/config.sample.php index eeaa9a7ef3d..f5ac9020046 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -936,16 +936,16 @@ $CONFIG = [ * * Defaults to the following domains: * - * - www.nextcloud.com - * - www.startpage.com - * - www.eff.org - * - www.edri.org + * - https://www.nextcloud.com + * - https://www.startpage.com + * - https://www.eff.org + * - https://www.edri.org */ 'connectivity_check_domains' => [ - 'www.nextcloud.com', - 'www.startpage.com', - 'www.eff.org', - 'www.edri.org' + 'https://www.nextcloud.com', + 'https://www.startpage.com', + 'https://www.eff.org', + 'https://www.edri.org' ], /** |