Skip to content

Commit 2a79fbf

Browse files
committed
perf: only check https if http fails
Signed-off-by: Josh Richards <josh.t.richards@gmail.com>
1 parent c62b2f8 commit 2a79fbf

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

apps/settings/lib/SetupChecks/InternetConnectivity.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public function run(): SetupResult {
4646

4747
foreach ($siteArray as $site) {
4848
if ($this->isSiteReachable($site)) {
49+
// successful as soon as one connection succeeds
4950
return SetupResult::success();
5051
}
5152
}
@@ -55,19 +56,18 @@ public function run(): SetupResult {
5556
/**
5657
* Checks if the Nextcloud server can connect to a specific URL
5758
* @param string $site site domain or full URL with http/https protocol
59+
* @return bool success/failure
5860
*/
5961
private function isSiteReachable(string $site): bool {
62+
// if there is no protocol specified, test http:// first then, if necessary, https://
63+
if (preg_match('/^https?:\/\//', $site) !== 1) {
64+
$httpSite = 'http://' . $site . '/';
65+
$httpsSite = 'https://' . $site . '/';
66+
return $this->isSiteReachable($httpSite) || $this->isSiteReachable($httpsSite);
67+
}
6068
try {
6169
$client = $this->clientService->newClient();
62-
// if there is no protocol, test http:// AND https://
63-
if (preg_match('/^https?:\/\//', $site) !== 1) {
64-
$httpSite = 'http://' . $site . '/';
65-
$client->get($httpSite);
66-
$httpsSite = 'https://' . $site . '/';
67-
$client->get($httpsSite);
68-
} else {
69-
$client->get($site);
70-
}
70+
$client->get($site);
7171
} catch (\Exception $e) {
7272
$this->logger->error('Cannot connect to: ' . $site, [
7373
'app' => 'internet_connection_check',

0 commit comments

Comments
 (0)