From 5a83a1b7281877a8dfba55038206c8567f6dbffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20K=C5=82os?= Date: Tue, 24 Nov 2020 11:18:49 +0100 Subject: Increase timeout if proxy is starting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Szymon Kłos --- lib/WOPI/DiscoveryManager.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'lib') 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) { -- cgit v1.2.3