diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2020-11-24 13:18:49 +0300 |
---|---|---|
committer | Szymon Kłos <szymon.klos@collabora.com> | 2020-11-24 14:34:45 +0300 |
commit | 5a83a1b7281877a8dfba55038206c8567f6dbffd (patch) | |
tree | e9b209d5b861caef34abe42d47a504df2631dddb /lib | |
parent | a1bada3394571eaff836b8cff39208f63778ea00 (diff) |
Increase timeout if proxy is starting
Signed-off-by: Szymon Kłos <szymon.klos@collabora.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/WOPI/DiscoveryManager.php | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/WOPI/DiscoveryManager.php b/lib/WOPI/DiscoveryManager.php index 585a0c76..5a2fd057 100644 --- a/lib/WOPI/DiscoveryManager.php +++ b/lib/WOPI/DiscoveryManager.php @@ -77,6 +77,35 @@ class DiscoveryManager { $options['verify'] = false; } + // first load with proxy can take some time - increase timeout in that case + $usesProxy = false; + $proxyPos = strrpos($wopiDiscovery, 'proxy.php'); + if ($proxyPos === false) + $usesProxy = false; + else + $usesProxy = true; + + if ($usesProxy === true) { + $statusUrl = substr($wopiDiscovery, 0, $proxyPos); + $statusUrl = $statusUrl . 'proxy.php?status'; + + 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') { + $options['timeout'] = 180; + } + } + } catch (\Exception $e) { + // ignore + } + } + try { return $client->get($wopiDiscovery, $options); } catch (\Exception $e) { |