Skip to content

Commit

Permalink
Merge pull request #40137 from summersab/refactor/OC-Server-getHTTPCl…
Browse files Browse the repository at this point in the history
…ientService

Refactor `OC\Server::getHTTPClientService`
  • Loading branch information
skjnldsv authored May 30, 2024
2 parents db4aaf4 + 91227c9 commit db60aca
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
5 changes: 3 additions & 2 deletions build/integration/features/bootstrap/RemoteContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
use Behat\Behat\Context\Context;
use OCP\Http\Client\IClientService;
use PHPUnit\Framework\Assert;

require __DIR__ . '/../../vendor/autoload.php';
Expand Down Expand Up @@ -31,7 +32,7 @@ public function __construct($remote) {
}

protected function getApiClient() {
return new \OC\Remote\Api\OCS($this->remoteInstance, $this->credentails, \OC::$server->getHTTPClientService());
return new \OC\Remote\Api\OCS($this->remoteInstance, $this->credentails, \OC::$server->get(IClientService::class));
}

/**
Expand All @@ -47,7 +48,7 @@ public function selectRemoteInstance($remoteServer) {
}
$this->lastException = null;
try {
$this->remoteInstance = new \OC\Remote\Instance($baseUri, \OC::$server->getMemCacheFactory()->createLocal(), \OC::$server->getHTTPClientService());
$this->remoteInstance = new \OC\Remote\Instance($baseUri, \OC::$server->getMemCacheFactory()->createLocal(), \OC::$server->get(IClientService::class));
// trigger the status request
$this->remoteInstance->getProtocol();
} catch (\Exception $e) {
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Storage/DAV.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class DAV extends Common {
*/
public function __construct($params) {
$this->statCache = new ArrayCache();
$this->httpClientService = \OC::$server->getHTTPClientService();
$this->httpClientService = \OC::$server->get(IClientService::class);
if (isset($params['host']) && isset($params['user']) && isset($params['password'])) {
$host = $params['host'];
//remove leading http[s], will be generated in createBaseUri()
Expand Down
3 changes: 2 additions & 1 deletion lib/private/Share20/ProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Federation\ICloudFederationFactory;
use OCP\Files\IRootFolder;
use OCP\Http\Client\IClientService;
use OCP\IServerContainer;
use OCP\Security\IHasher;
use OCP\Share\IManager;
Expand Down Expand Up @@ -115,7 +116,7 @@ protected function federatedShareProvider() {
);
$notifications = new Notifications(
$addressHandler,
$this->serverContainer->getHTTPClientService(),
$this->serverContainer->get(IClientService::class),
$this->serverContainer->query(\OCP\OCS\IDiscoveryService::class),
$this->serverContainer->getJobList(),
\OC::$server->getCloudFederationProviderManager(),
Expand Down
5 changes: 3 additions & 2 deletions lib/private/legacy/OC_Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use OC\Authentication\TwoFactorAuth\Manager as TwoFactorAuthManager;
use OC\Files\SetupManager;
use OCP\Files\Template\ITemplateManager;
use OCP\Http\Client\IClientService;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IURLGenerator;
Expand Down Expand Up @@ -877,7 +878,7 @@ public function isHtaccessWorking(\OCP\IConfig $config) {
// accessing the file via http
$url = \OC::$server->getURLGenerator()->getAbsoluteURL(OC::$WEBROOT . '/data' . $fileName);
try {
$content = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody();
$content = \OC::$server->get(IClientService::class)->newClient()->get($url)->getBody();
} catch (\Exception $e) {
$content = false;
}
Expand All @@ -889,7 +890,7 @@ public function isHtaccessWorking(\OCP\IConfig $config) {
}

try {
$fallbackContent = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody();
$fallbackContent = \OC::$server->get(IClientService::class)->newClient()->get($url)->getBody();
} catch (\Exception $e) {
$fallbackContent = false;
}
Expand Down
6 changes: 3 additions & 3 deletions tests/lib/InstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected function setUp(): void {
$config->setSystemValue('appstoreenabled', true);
$installer = new Installer(
\OC::$server->get(AppFetcher::class),
\OC::$server->getHTTPClientService(),
\OC::$server->get(IClientService::class),
\OC::$server->getTempManager(),
\OC::$server->get(LoggerInterface::class),
$config,
Expand All @@ -74,7 +74,7 @@ protected function getInstaller() {
protected function tearDown(): void {
$installer = new Installer(
\OC::$server->get(AppFetcher::class),
\OC::$server->getHTTPClientService(),
\OC::$server->get(IClientService::class),
\OC::$server->getTempManager(),
\OC::$server->get(LoggerInterface::class),
\OC::$server->getConfig(),
Expand All @@ -98,7 +98,7 @@ public function testInstallApp() {
// Install app
$installer = new Installer(
\OC::$server->get(AppFetcher::class),
\OC::$server->getHTTPClientService(),
\OC::$server->get(IClientService::class),
\OC::$server->getTempManager(),
\OC::$server->get(LoggerInterface::class),
\OC::$server->getConfig(),
Expand Down

0 comments on commit db60aca

Please sign in to comment.