Skip to content

Commit

Permalink
Merge pull request #1269 from eszkadev/increase-proxy-timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
juliushaertl committed Dec 3, 2020
2 parents f27c48e + ca705a4 commit bea5976
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions lib/WOPI/DiscoveryManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ public function fetchFromRemote() {
$options['verify'] = false;
}

if ($this->isProxyStarting($wopiDiscovery))
$options['timeout'] = 180;

try {
return $client->get($wopiDiscovery, $options);
} catch (\Exception $e) {
Expand All @@ -88,4 +91,46 @@ public function refetch() {
$this->cache->remove('discovery');
$this->discovery = null;
}

/**
* @return boolean indicating if proxy.php is in initialize or false otherwise
*/
private function isProxyStarting($url) {
$usesProxy = false;
$proxyPos = strrpos($url, 'proxy.php');
if ($proxyPos === false)
$usesProxy = false;
else
$usesProxy = true;

if ($usesProxy === true) {
$statusUrl = substr($url, 0, $proxyPos);
$statusUrl = $statusUrl . 'proxy.php?status';

$client = $this->clientService->newClient();
$options = ['timeout' => 5, 'nextcloud' => ['allow_local_address' => true]];

if ($this->config->getAppValue('richdocuments', 'disable_certificate_verification') === 'yes') {
$options['verify'] = false;
}

try {
$response = $client->get($statusUrl, $options);

if ($response->getStatusCode() === 200) {
$body = json_decode($response->getBody(), true);

if ($body['status'] === 'starting'
|| $body['status'] === 'stopped'
|| $body['status'] === 'restarting') {
return true;
}
}
} catch (\Exception $e) {
// ignore
}
}

return false;
}
}

0 comments on commit bea5976

Please sign in to comment.