Merge pull request #25123 from owncloud/issue-23005-broken-remote-shares

Add timeouts to make the UI usable again when a remote share is unrea…
This commit is contained in:
Vincent Petry 2016-06-22 15:52:44 +02:00 committed by GitHub
commit 963d8a8565
5 changed files with 40 additions and 10 deletions

View File

@ -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' => 10,
'connect_timeout' => 10,
]);
if($response->getStatusCode() === 200) {
$decodedService = json_decode($response->getBody(), true);
if(is_array($decodedService)) {

View File

@ -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' => 10,
'connect_timeout' => 10,
]);
$result['result'] = $response->getBody();
$result['success'] = true;

View File

@ -77,7 +77,10 @@ class DiscoveryManagerTest extends \Test\TestCase {
$this->client
->expects($this->once())
->method('get')
->with('https://myhost.com/ocs-provider/', [])
->with('https://myhost.com/ocs-provider/', [
'timeout' => 10,
'connect_timeout' => 10,
])
->willReturn($response);
$this->cache
->expects($this->at(0))
@ -111,7 +114,10 @@ class DiscoveryManagerTest extends \Test\TestCase {
$this->client
->expects($this->once())
->method('get')
->with('https://myhost.com/ocs-provider/', [])
->with('https://myhost.com/ocs-provider/', [
'timeout' => 10,
'connect_timeout' => 10,
])
->willReturn($response);
$expectedResult = '/public.php/MyCustomEndpoint/';
@ -131,7 +137,10 @@ class DiscoveryManagerTest extends \Test\TestCase {
$this->client
->expects($this->once())
->method('get')
->with('https://myhost.com/ocs-provider/', [])
->with('https://myhost.com/ocs-provider/', [
'timeout' => 10,
'connect_timeout' => 10,
])
->willReturn($response);
$expectedResult = '/public.php/webdav';
@ -151,7 +160,10 @@ class DiscoveryManagerTest extends \Test\TestCase {
$this->client
->expects($this->once())
->method('get')
->with('https://myhost.com/ocs-provider/', [])
->with('https://myhost.com/ocs-provider/', [
'timeout' => 10,
'connect_timeout' => 10,
])
->willReturn($response);
$expectedResult = '/ocs/v2.php/cloud/MyCustomShareEndpoint';
@ -171,7 +183,10 @@ class DiscoveryManagerTest extends \Test\TestCase {
$this->client
->expects($this->once())
->method('get')
->with('https://myhost.com/ocs-provider/', [])
->with('https://myhost.com/ocs-provider/', [
'timeout' => 10,
'connect_timeout' => 10,
])
->willReturn($response);
$this->cache
->expects($this->at(0))

View File

@ -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' => 10,
'connect_timeout' => 10,
])->getBody();
} catch (\Exception $e) {
\OCP\JSON::error(array('data' => array('message' => $l->t('Invalid or untrusted SSL certificate'))));
exit;

View File

@ -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' => 10,
'connect_timeout' => 10,
])->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' => 10,
'connect_timeout' => 10,
]);
} catch (\GuzzleHttp\Exception\RequestException $e) {
if ($e->getCode() === 401 || $e->getCode() === 403) {
throw new ForbiddenException();