summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Reschke <lukas@owncloud.com>2016-03-08 22:13:00 +0100
committerLukas Reschke <lukas@owncloud.com>2016-03-08 22:13:00 +0100
commit8214fae9aeb4182fe5e9aecb6414713eb800e85b (patch)
tree5abab9226b4df82f96dc490ad0b7ec94fa83dd53
parent8c8ff0eae739206afe14c454df9790d27f303318 (diff)
downloadnextcloud-server-8214fae9aeb4182fe5e9aecb6414713eb800e85b.tar.gz
nextcloud-server-8214fae9aeb4182fe5e9aecb6414713eb800e85b.zip
Use HTTPClient instead of file_get_contents
Allows us to catch exceptions like 404's and thus prevents stuff like: ``` {"reqId":"fnmS0hc+fL4+WXKAruo5","remoteAddr":"192.168.39.100","app":"PHP","message":"file_get_contents(http:\/\/ckamm.blaucloud.de\/\/status.php): failed to open stream: HTTP request failed! HTTP\/1.1 404 Not Found\r\n at \/var\/www\/owncloud\/apps\/files_sharing\/lib\/external\/storage.php#260","level":3,"time":"2016-03-08T21:00:33+00:00","method":"PROPFIND","url":"\/remote.php\/webdav\/"} ```
-rw-r--r--apps/files_sharing/lib/external/storage.php50
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 87f5a3598fb..841a28dba8e 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)$result;
}
- $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;
}