diff options
author | Julius Härtl <jus@bitgrid.net> | 2020-12-03 11:53:52 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-03 11:53:52 +0300 |
commit | bea59761960f0e54d68a1d58fd8b55844c7b0b84 (patch) | |
tree | 7db39be0412fd2c8f14aebec3dd7fbf48272a598 /lib | |
parent | f27c48e5a4cdd1d6546728ed9c20773d7d11064b (diff) | |
parent | ca705a471ecd78b08a6cd097e44b8e7cb769ed1b (diff) |
Merge pull request #1269 from eszkadev/increase-proxy-timeout
Diffstat (limited to 'lib')
-rw-r--r-- | lib/WOPI/DiscoveryManager.php | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/WOPI/DiscoveryManager.php b/lib/WOPI/DiscoveryManager.php index 585a0c76..d8d70b58 100644 --- a/lib/WOPI/DiscoveryManager.php +++ b/lib/WOPI/DiscoveryManager.php @@ -77,6 +77,9 @@ class DiscoveryManager { $options['verify'] = false; } + if ($this->isProxyStarting($wopiDiscovery)) + $options['timeout'] = 180; + try { return $client->get($wopiDiscovery, $options); } catch (\Exception $e) { @@ -88,4 +91,46 @@ class DiscoveryManager { $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; + } } |