* Remove the HTTP Helper * Remove from Server Containter * Removed legacy share tests that use it Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>pull/8804/head
parent
ede723f1b1
commit
7785c3752f
@ -1,120 +0,0 @@ |
||||
<?php |
||||
/** |
||||
* @copyright Copyright (c) 2016, ownCloud, Inc. |
||||
* |
||||
* @author Björn Schießle <bjoern@schiessle.org> |
||||
* @author Lukas Reschke <lukas@statuscode.ch> |
||||
* @author Morris Jobke <hey@morrisjobke.de> |
||||
* |
||||
* @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 <http://www.gnu.org/licenses/> |
||||
* |
||||
*/ |
||||
|
||||
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()]; |
||||
} |
||||
|
||||
} |
||||
@ -1,123 +0,0 @@ |
||||
<?php |
||||
/** |
||||
* Copyright (c) 2014 Lukas Reschke <lukas@owncloud.com> |
||||
* This file is licensed under the Affero General Public License version 3 or |
||||
* later. |
||||
* See the COPYING-README file. |
||||
*/ |
||||
|
||||
namespace Test; |
||||
|
||||
use OCP\Http\Client\IClientService; |
||||
use OCP\IConfig; |
||||
|
||||
class HTTPHelperTest extends \Test\TestCase { |
||||
|
||||
/** @var \OCP\IConfig*/ |
||||
private $config; |
||||
/** @var \OC\HTTPHelper */ |
||||
private $httpHelperMock; |
||||
/** @var \OCP\Http\Client\IClientService */ |
||||
private $clientService; |
||||
|
||||
protected function setUp() { |
||||
parent::setUp(); |
||||
|
||||
$this->config = $this->getMockBuilder(IConfig::class) |
||||
->disableOriginalConstructor()->getMock(); |
||||
$this->clientService = $this->createMock(IClientService::class); |
||||
$this->httpHelperMock = $this->getMockBuilder('\OC\HTTPHelper') |
||||
->setConstructorArgs(array($this->config, $this->clientService)) |
||||
->setMethods(array('getHeaders')) |
||||
->getMock(); |
||||
} |
||||
|
||||
public function isHttpTestData() { |
||||
return array( |
||||
array('http://wwww.owncloud.org/enterprise/', true), |
||||
array('https://wwww.owncloud.org/enterprise/', true), |
||||
array('HTTPS://WWW.OWNCLOUD.ORG', true), |
||||
array('HTTP://WWW.OWNCLOUD.ORG', true), |
||||
array('FILE://WWW.OWNCLOUD.ORG', false), |
||||
array('file://www.owncloud.org', false), |
||||
array('FTP://WWW.OWNCLOUD.ORG', false), |
||||
array('ftp://www.owncloud.org', false), |
||||
); |
||||
} |
||||
|
||||
/** |
||||
* @dataProvider isHttpTestData |
||||
*/ |
||||
public function testIsHTTP($url, $expected) { |
||||
$this->assertSame($expected, $this->httpHelperMock->isHTTPURL($url)); |
||||
} |
||||
|
||||
public function testPostSuccess() { |
||||
$client = $this->getMockBuilder('\OCP\Http\Client\IClient') |
||||
->disableOriginalConstructor()->getMock(); |
||||
$this->clientService |
||||
->expects($this->once()) |
||||
->method('newClient') |
||||
->will($this->returnValue($client)); |
||||
$response = $this->getMockBuilder('\OCP\Http\Client\IResponse') |
||||
->disableOriginalConstructor()->getMock(); |
||||
$client |
||||
->expects($this->once()) |
||||
->method('post') |
||||
->with( |
||||
'https://owncloud.org', |
||||
[ |
||||
'body' => [ |
||||
'Foo' => 'Bar', |
||||
], |
||||
'connect_timeout' => 10, |
||||
|
||||
] |
||||
) |
||||
->will($this->returnValue($response)); |
||||
$response |
||||
->expects($this->once()) |
||||
->method('getBody') |
||||
->will($this->returnValue('Body of the requested page')); |
||||
|
||||
|
||||
$response = $this->httpHelperMock->post('https://owncloud.org', ['Foo' => 'Bar']); |
||||
$expected = [ |
||||
'success' => true, |
||||
'result' => 'Body of the requested page' |
||||
]; |
||||
$this->assertSame($expected, $response); |
||||
} |
||||
|
||||
public function testPostException() { |
||||
$client = $this->getMockBuilder('\OCP\Http\Client\IClient') |
||||
->disableOriginalConstructor()->getMock(); |
||||
$this->clientService |
||||
->expects($this->once()) |
||||
->method('newClient') |
||||
->will($this->returnValue($client)); |
||||
$client |
||||
->expects($this->once()) |
||||
->method('post') |
||||
->with( |
||||
'https://owncloud.org', |
||||
[ |
||||
'body' => [ |
||||
'Foo' => 'Bar', |
||||
], |
||||
'connect_timeout' => 10, |
||||
|
||||
] |
||||
) |
||||
->will($this->throwException(new \Exception('Something failed'))); |
||||
|
||||
|
||||
$response = $this->httpHelperMock->post('https://owncloud.org', ['Foo' => 'Bar']); |
||||
$expected = [ |
||||
'success' => false, |
||||
'result' => 'Something failed' |
||||
]; |
||||
$this->assertSame($expected, $response); |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue