From 7785c3752fbfef792cd33dc5da2ee63e8263b9fa Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Tue, 13 Mar 2018 16:30:41 +0100 Subject: Remove deprecated HTTPHelper * Remove the HTTP Helper * Remove from Server Containter * Removed legacy share tests that use it Signed-off-by: Roeland Jago Douma --- lib/private/HTTPHelper.php | 120 -------------------------------------------- lib/private/Server.php | 17 ------- lib/private/Share/Share.php | 17 ++++++- 3 files changed, 16 insertions(+), 138 deletions(-) delete mode 100644 lib/private/HTTPHelper.php (limited to 'lib/private') diff --git a/lib/private/HTTPHelper.php b/lib/private/HTTPHelper.php deleted file mode 100644 index d58f81fbbdc..00000000000 --- a/lib/private/HTTPHelper.php +++ /dev/null @@ -1,120 +0,0 @@ - - * @author Lukas Reschke - * @author Morris Jobke - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see - * - */ - -namespace OC; - -use OCP\Http\Client\IClientService; -use OCP\IConfig; - -/** - * Class HTTPHelper - * - * @package OC - * @deprecated Use \OCP\Http\Client\IClientService - */ -class HTTPHelper { - const USER_AGENT = 'ownCloud Server Crawler'; - - /** @var \OCP\IConfig */ - private $config; - /** @var IClientService */ - private $clientService; - - /** - * @param IConfig $config - * @param IClientService $clientService - */ - public function __construct(IConfig $config, - IClientService $clientService) { - $this->config = $config; - $this->clientService = $clientService; - } - - /** - * Get URL content - * @param string $url Url to get content - * @throws \Exception If the URL does not start with http:// or https:// - * @return string of the response or false on error - * This function get the content of a page via curl, if curl is enabled. - * If not, file_get_contents is used. - * @deprecated Use \OCP\Http\Client\IClientService - */ - public function getUrlContent($url) { - try { - $client = $this->clientService->newClient(); - $response = $client->get($url); - return $response->getBody(); - } catch (\Exception $e) { - return false; - } - } - - /** - * Returns the response headers of a HTTP URL without following redirects - * @param string $location Needs to be a HTTPS or HTTP URL - * @return array - * @deprecated Use \OCP\Http\Client\IClientService - */ - public function getHeaders($location) { - $client = $this->clientService->newClient(); - $response = $client->get($location); - return $response->getHeaders(); - } - - /** - * Checks whether the supplied URL begins with HTTPS:// or HTTP:// (case insensitive) - * @param string $url - * @return bool - */ - public function isHTTPURL($url) { - return stripos($url, 'https://') === 0 || stripos($url, 'http://') === 0; - } - - /** - * send http post request - * - * @param string $url - * @param array $fields data send by the request - * @return array - * @deprecated Use \OCP\Http\Client\IClientService - */ - public function post($url, array $fields) { - $client = $this->clientService->newClient(); - - try { - $response = $client->post( - $url, - [ - 'body' => $fields, - 'connect_timeout' => 10, - ] - ); - } catch (\Exception $e) { - return ['success' => false, 'result' => $e->getMessage()]; - } - - return ['success' => true, 'result' => $response->getBody()]; - } - -} diff --git a/lib/private/Server.php b/lib/private/Server.php index af739c91b02..09807b185da 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -630,13 +630,6 @@ class Server extends ServerContainer implements IServerContainer { }); $this->registerAlias('DatabaseConnection', IDBConnection::class); - $this->registerService('HTTPHelper', function (Server $c) { - $config = $c->getConfig(); - return new HTTPHelper( - $config, - $c->getHTTPClientService() - ); - }); $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { $user = \OC_User::getUser(); @@ -1582,16 +1575,6 @@ class Server extends ServerContainer implements IServerContainer { return $this->query('CredentialsManager'); } - /** - * Returns an instance of the HTTP helper class - * - * @deprecated Use getHTTPClientService() - * @return \OC\HTTPHelper - */ - public function getHTTPHelper() { - return $this->query('HTTPHelper'); - } - /** * Get the certificate manager for the user * diff --git a/lib/private/Share/Share.php b/lib/private/Share/Share.php index e6056679c1c..4514cdbae1b 100644 --- a/lib/private/Share/Share.php +++ b/lib/private/Share/Share.php @@ -1991,7 +1991,22 @@ class Share extends Constants { while ($result['success'] === false && $try < 2) { $federationEndpoints = $discoveryService->discover($protocol . $remoteDomain, 'FEDERATED_SHARING'); $endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares'; - $result = \OC::$server->getHTTPHelper()->post($protocol . $remoteDomain . $endpoint . $urlSuffix . '?format=' . self::RESPONSE_FORMAT, $fields); + $client = \OC::$server->getHTTPClientService()->newClient(); + + try { + $response = $client->post( + $protocol . $remoteDomain . $endpoint . $urlSuffix . '?format=' . self::RESPONSE_FORMAT, + [ + 'body' => $fields, + 'connect_timeout' => 10, + ] + ); + + $result = ['success' => true, 'result' => $response->getBody()]; + } catch (\Exception $e) { + $result = ['success' => false, 'result' => $e->getMessage()]; + } + $try++; $protocol = 'http://'; } -- cgit v1.2.3