summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2016-06-15 16:30:24 +0200
committerVincent Petry <pvince81@owncloud.com>2016-06-22 10:29:40 +0200
commit3e763ac81e895d2b4af18af2bcd7a31e25da4cf6 (patch)
tree12539e73e95bb8938ba63beedd078933a132592e
parentb85bcccc09746137dd6fed78629b5bce45cebe01 (diff)
downloadnextcloud-server-3e763ac81e895d2b4af18af2bcd7a31e25da4cf6.tar.gz
nextcloud-server-3e763ac81e895d2b4af18af2bcd7a31e25da4cf6.zip
Add timeouts to make the UI usable again when a remote share is unreachable
-rw-r--r--apps/federatedfilesharing/lib/DiscoveryManager.php5
-rw-r--r--apps/federatedfilesharing/lib/Notifications.php4
-rw-r--r--apps/files_sharing/ajax/external.php5
-rw-r--r--apps/files_sharing/lib/External/Storage.php11
4 files changed, 20 insertions, 5 deletions
diff --git a/apps/federatedfilesharing/lib/DiscoveryManager.php b/apps/federatedfilesharing/lib/DiscoveryManager.php
index 2a4bb4b7f77..bf8dfeb31dc 100644
--- a/apps/federatedfilesharing/lib/DiscoveryManager.php
+++ b/apps/federatedfilesharing/lib/DiscoveryManager.php
@@ -84,7 +84,10 @@ class DiscoveryManager {
// Read the data from the response body
try {
- $response = $this->client->get($remote . '/ocs-provider/');
+ $response = $this->client->get($remote . '/ocs-provider/', [
+ 'timeout' => 3,
+ 'connect_timeout' => 3,
+ ]);
if($response->getStatusCode() === 200) {
$decodedService = json_decode($response->getBody(), true);
if(is_array($decodedService)) {
diff --git a/apps/federatedfilesharing/lib/Notifications.php b/apps/federatedfilesharing/lib/Notifications.php
index 18212b82c3e..575521d564d 100644
--- a/apps/federatedfilesharing/lib/Notifications.php
+++ b/apps/federatedfilesharing/lib/Notifications.php
@@ -287,7 +287,9 @@ class Notifications {
$endpoint = $this->discoveryManager->getShareEndpoint($protocol . $remoteDomain);
try {
$response = $client->post($protocol . $remoteDomain . $endpoint . $urlSuffix . '?format=' . self::RESPONSE_FORMAT, [
- 'body' => $fields
+ 'body' => $fields,
+ 'timeout' => 3,
+ 'connect_timeout' => 3,
]);
$result['result'] = $response->getBody();
$result['success'] = true;
diff --git a/apps/files_sharing/ajax/external.php b/apps/files_sharing/ajax/external.php
index 5cf86087f94..6a0a4dfc06b 100644
--- a/apps/files_sharing/ajax/external.php
+++ b/apps/files_sharing/ajax/external.php
@@ -77,7 +77,10 @@ $externalManager = new \OCA\Files_Sharing\External\Manager(
// check for ssl cert
if (substr($remote, 0, 5) === 'https') {
try {
- \OC::$server->getHTTPClientService()->newClient()->get($remote)->getBody();
+ \OC::$server->getHTTPClientService()->newClient()->get($remote, [
+ 'timeout' => 3,
+ 'connect_timeout' => 3,
+ ])->getBody();
} catch (\Exception $e) {
\OCP\JSON::error(array('data' => array('message' => $l->t('Invalid or untrusted SSL certificate'))));
exit;
diff --git a/apps/files_sharing/lib/External/Storage.php b/apps/files_sharing/lib/External/Storage.php
index ca99393a1e0..7302de5f934 100644
--- a/apps/files_sharing/lib/External/Storage.php
+++ b/apps/files_sharing/lib/External/Storage.php
@@ -254,7 +254,10 @@ class Storage extends DAV implements ISharedStorage {
$client = $this->httpClient->newClient();
try {
- $result = $client->get($url)->getBody();
+ $result = $client->get($url, [
+ 'timeout' => 3,
+ 'connect_timeout' => 3,
+ ])->getBody();
$data = json_decode($result);
$returnValue = (is_object($data) && !empty($data->version));
} catch (ConnectException $e) {
@@ -301,7 +304,11 @@ class Storage extends DAV implements ISharedStorage {
// TODO: DI
$client = \OC::$server->getHTTPClientService()->newClient();
try {
- $response = $client->post($url, ['body' => ['password' => $password]]);
+ $response = $client->post($url, [
+ 'body' => ['password' => $password],
+ 'timeout' => 3,
+ 'connect_timeout' => 3,
+ ]);
} catch (\GuzzleHttp\Exception\RequestException $e) {
if ($e->getCode() === 401 || $e->getCode() === 403) {
throw new ForbiddenException();