Skip to content

Commit

Permalink
perf: only check https if http fails
Browse files Browse the repository at this point in the history
Signed-off-by: Josh Richards <[email protected]>
  • Loading branch information
joshtrichards committed Jan 7, 2025
1 parent c62b2f8 commit 2a79fbf
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions apps/settings/lib/SetupChecks/InternetConnectivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function run(): SetupResult {

foreach ($siteArray as $site) {
if ($this->isSiteReachable($site)) {
// successful as soon as one connection succeeds
return SetupResult::success();
}
}
Expand All @@ -55,19 +56,18 @@ public function run(): SetupResult {
/**
* 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',
Expand Down

0 comments on commit 2a79fbf

Please sign in to comment.