diff options
author | Morris Jobke <hey@morrisjobke.de> | 2015-03-26 11:06:48 +0100 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2015-03-26 11:06:48 +0100 |
commit | 20f5290462cddee766025bd5671430836b054cc8 (patch) | |
tree | a0b33a654f6fa2ed4c75dffd9f65ddd437ada90f /lib/private/ocsclient.php | |
parent | c8f0cbab5a994aadfaa9c984bb9959ca872fe781 (diff) | |
parent | 5f044ebf1bc6f45acec2e79dc05185acd0405f42 (diff) | |
download | nextcloud-server-20f5290462cddee766025bd5671430836b054cc8.tar.gz nextcloud-server-20f5290462cddee766025bd5671430836b054cc8.zip |
Merge pull request #15195 from owncloud/reanimate-add-guzzle
Add wrapper for Guzzle
Diffstat (limited to 'lib/private/ocsclient.php')
-rw-r--r-- | lib/private/ocsclient.php | 59 |
1 files changed, 42 insertions, 17 deletions
diff --git a/lib/private/ocsclient.php b/lib/private/ocsclient.php index f27ab487efc..1e09d409297 100644 --- a/lib/private/ocsclient.php +++ b/lib/private/ocsclient.php @@ -67,16 +67,24 @@ class OCSClient { return null; } $url = self::getAppStoreURL() . '/content/categories'; - $xml = \OC::$server->getHTTPHelper()->getUrlContent($url); - if ($xml == false) { + + $client = \OC::$server->getHTTPClientService()->newClient(); + try { + $response = $client->get($url, ['timeout' => 5]); + } catch(\Exception $e) { + return null; + } + + if($response->getStatusCode() !== 200) { return null; } + $loadEntities = libxml_disable_entity_loader(true); - $data = simplexml_load_string($xml); + $data = simplexml_load_string($response->getBody()); libxml_disable_entity_loader($loadEntities); $tmp = $data->data; - $cats = array(); + $cats = []; foreach ($tmp->category as $value) { @@ -114,14 +122,21 @@ class OCSClient { $filterUrl = '&filter=' . urlencode($filter); $url = self::getAppStoreURL() . '/content/data?categories=' . urlencode($categoriesString) . '&sortmode=new&page=' . urlencode($page) . '&pagesize=100' . $filterUrl . $version; - $apps = array(); - $xml = \OC::$server->getHTTPHelper()->getUrlContent($url); + $apps = []; + + $client = \OC::$server->getHTTPClientService()->newClient(); + try { + $response = $client->get($url, ['timeout' => 5]); + } catch(\Exception $e) { + return null; + } - if ($xml == false) { + if($response->getStatusCode() !== 200) { return null; } + $loadEntities = libxml_disable_entity_loader(true); - $data = simplexml_load_string($xml); + $data = simplexml_load_string($response->getBody()); libxml_disable_entity_loader($loadEntities); $tmp = $data->data->content; @@ -163,14 +178,19 @@ class OCSClient { return null; } $url = self::getAppStoreURL() . '/content/data/' . urlencode($id); - $xml = \OC::$server->getHTTPHelper()->getUrlContent($url); + $client = \OC::$server->getHTTPClientService()->newClient(); + try { + $response = $client->get($url, ['timeout' => 5]); + } catch(\Exception $e) { + return null; + } - if ($xml == false) { - \OC_Log::write('core', 'Unable to parse OCS content for app ' . $id, \OC_Log::FATAL); + if($response->getStatusCode() !== 200) { return null; } + $loadEntities = libxml_disable_entity_loader(true); - $data = simplexml_load_string($xml); + $data = simplexml_load_string($response->getBody()); libxml_disable_entity_loader($loadEntities); $tmp = $data->data->content; @@ -178,7 +198,7 @@ class OCSClient { \OC_Log::write('core', 'Invalid OCS content returned for app ' . $id, \OC_Log::FATAL); return null; } - $app = array(); + $app = []; $app['id'] = $tmp->id; $app['name'] = $tmp->name; $app['version'] = $tmp->version; @@ -212,14 +232,19 @@ class OCSClient { return null; } $url = self::getAppStoreURL() . '/content/download/' . urlencode($id) . '/' . urlencode($item); - $xml = \OC::$server->getHTTPHelper()->getUrlContent($url); + $client = \OC::$server->getHTTPClientService()->newClient(); + try { + $response = $client->get($url, ['timeout' => 5]); + } catch(\Exception $e) { + return null; + } - if ($xml == false) { - \OC_Log::write('core', 'Unable to parse OCS content', \OC_Log::FATAL); + if($response->getStatusCode() !== 200) { return null; } + $loadEntities = libxml_disable_entity_loader(true); - $data = simplexml_load_string($xml); + $data = simplexml_load_string($response->getBody()); libxml_disable_entity_loader($loadEntities); $tmp = $data->data->content; |