diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2016-03-09 12:20:06 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-03-09 12:20:06 +0100 |
commit | 30cec687ae788fcabe901c3302b260563822fa56 (patch) | |
tree | 80e0b3c560d2b8907f250a6ed5c51d88c794e282 /apps | |
parent | 36084218008573d52b0fd5d7f4e0181a3c49d593 (diff) | |
parent | 8214fae9aeb4182fe5e9aecb6414713eb800e85b (diff) | |
download | nextcloud-server-30cec687ae788fcabe901c3302b260563822fa56.tar.gz nextcloud-server-30cec687ae788fcabe901c3302b260563822fa56.zip |
Merge pull request #22972 from owncloud/use-httpclient-instead-of-file-get-contents
Use HTTPClient instead of file_get_contents
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files_sharing/lib/external/storage.php | 50 |
1 files changed, 23 insertions, 27 deletions
diff --git a/apps/files_sharing/lib/external/storage.php b/apps/files_sharing/lib/external/storage.php index 80ab006f1ca..16fd84bdba5 100644 --- a/apps/files_sharing/lib/external/storage.php +++ b/apps/files_sharing/lib/external/storage.php @@ -25,6 +25,8 @@ namespace OCA\Files_Sharing\External; +use GuzzleHttp\Exception\ClientException; +use GuzzleHttp\Exception\ConnectException; use OC\Files\Storage\DAV; use OC\ForbiddenException; use OCA\FederatedFileSharing\DiscoveryManager; @@ -34,36 +36,21 @@ use OCP\Files\StorageInvalidException; use OCP\Files\StorageNotAvailableException; class Storage extends DAV implements ISharedStorage { - /** - * @var string - */ + /** @var string */ private $remoteUser; - - /** - * @var string - */ + /** @var string */ private $remote; - - /** - * @var string - */ + /** @var string */ private $mountPoint; - - /** - * @var string - */ + /** @var string */ private $token; - - /** - * @var \OCP\ICacheFactory - */ + /** @var \OCP\ICacheFactory */ private $memcacheFactory; - - /** - * @var \OCP\ICertificateManager - */ + /** @var \OCP\Http\Client\IClientService */ + private $httpClient; + /** @var \OCP\ICertificateManager */ private $certificateManager; - + /** @var bool */ private $updateChecked = false; /** @@ -73,6 +60,7 @@ class Storage extends DAV implements ISharedStorage { public function __construct($options) { $this->memcacheFactory = \OC::$server->getMemCacheFactory(); + $this->httpClient = \OC::$server->getHTTPClientService(); $discoveryManager = new DiscoveryManager( $this->memcacheFactory, \OC::$server->getHTTPClientService() @@ -257,9 +245,17 @@ class Storage extends DAV implements ISharedStorage { return (bool)$cache->get($url); } - $result = file_get_contents($url); - $data = json_decode($result); - $returnValue = (is_object($data) and !empty($data->version)); + $client = $this->httpClient->newClient(); + try { + $result = $client->get($url)->getBody(); + $data = json_decode($result); + $returnValue = (is_object($data) && !empty($data->version)); + } catch (ConnectException $e) { + $returnValue = false; + } catch (ClientException $e) { + $returnValue = false; + } + $cache->set($url, $returnValue); return $returnValue; } |