Skip to content

Commit

Permalink
Merge pull request #3993 from nextcloud/backport/3831/stable28
Browse files Browse the repository at this point in the history
[stable28] fix(client): Use shared default options for HTTP client requests
  • Loading branch information
elzody authored Sep 6, 2024
2 parents 4434aca + 2740840 commit 1eda253
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
1 change: 1 addition & 0 deletions composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
'OCA\\Richdocuments\\Service\\FileTargetService' => $baseDir . '/../lib/Service/FileTargetService.php',
'OCA\\Richdocuments\\Service\\FontService' => $baseDir . '/../lib/Service/FontService.php',
'OCA\\Richdocuments\\Service\\InitialStateService' => $baseDir . '/../lib/Service/InitialStateService.php',
'OCA\\Richdocuments\\Service\\RemoteOptionsService' => $baseDir . '/../lib/Service/RemoteOptionsService.php',
'OCA\\Richdocuments\\Service\\RemoteService' => $baseDir . '/../lib/Service/RemoteService.php',
'OCA\\Richdocuments\\Service\\UserScopeService' => $baseDir . '/../lib/Service/UserScopeService.php',
'OCA\\Richdocuments\\Settings\\Admin' => $baseDir . '/../lib/Settings/Admin.php',
Expand Down
1 change: 1 addition & 0 deletions composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class ComposerStaticInitRichdocuments
'OCA\\Richdocuments\\Service\\FileTargetService' => __DIR__ . '/..' . '/../lib/Service/FileTargetService.php',
'OCA\\Richdocuments\\Service\\FontService' => __DIR__ . '/..' . '/../lib/Service/FontService.php',
'OCA\\Richdocuments\\Service\\InitialStateService' => __DIR__ . '/..' . '/../lib/Service/InitialStateService.php',
'OCA\\Richdocuments\\Service\\RemoteOptionsService' => __DIR__ . '/..' . '/../lib/Service/RemoteOptionsService.php',
'OCA\\Richdocuments\\Service\\RemoteService' => __DIR__ . '/..' . '/../lib/Service/RemoteService.php',
'OCA\\Richdocuments\\Service\\UserScopeService' => __DIR__ . '/..' . '/../lib/Service/UserScopeService.php',
'OCA\\Richdocuments\\Settings\\Admin' => __DIR__ . '/..' . '/../lib/Settings/Admin.php',
Expand Down
12 changes: 6 additions & 6 deletions lib/Preview/Office.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

use OC\Preview\Provider;
use OCA\Richdocuments\Capabilities;
use OCA\Richdocuments\Service\RemoteOptionsService;
use OCP\Files\FileInfo;
use OCP\Http\Client\IClientService;
use OCP\IConfig;
use OCP\ILogger;
Expand Down Expand Up @@ -53,7 +55,7 @@ private function getWopiURL() {
return $this->config->getAppValue('richdocuments', 'wopi_url');
}

public function isAvailable(\OCP\Files\FileInfo $file) {
public function isAvailable(FileInfo $file) {
if (isset($this->capabilitites['collabora']['convert-to']['available'])) {
return (bool)$this->capabilitites['collabora']['convert-to']['available'];
}
Expand All @@ -78,11 +80,9 @@ public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
}

$client = $this->clientService->newClient();
$options = [
'timeout' => 25,
// FIXME: Can be removed once https://github.com/CollaboraOnline/online/issues/6983 is fixed upstream
'expect' => false,
];
$options = RemoteOptionsService::getDefaultOptions();
// FIXME: can be removed once https://github.com/CollaboraOnline/online/issues/6983 is fixed upstream
$options['expect'] = false;

if ($this->config->getAppValue('richdocuments', 'disable_certificate_verification') === 'yes') {
$options['verify'] = false;
Expand Down
23 changes: 23 additions & 0 deletions lib/Service/RemoteOptionsService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/

namespace OCA\Richdocuments\Service;

class RemoteOptionsService {
public const REMOTE_TIMEOUT_DEFAULT = 5;

public static function getDefaultOptions(int $timeout = self::REMOTE_TIMEOUT_DEFAULT): array {
return [
'timeout' => $timeout,
'nextcloud' => [
'allow_local_address' => true,
]
];
}

}
13 changes: 4 additions & 9 deletions lib/Service/RemoteService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
use Psr\Log\LoggerInterface;

class RemoteService {

public const REMOTE_TIMEOUT_DEFAULT = 25;

public function __construct(
private AppConfig $appConfig,
private IClientService $clientService,
Expand Down Expand Up @@ -66,12 +63,10 @@ private function getRequestOptionsForFile(File $file, ?string $target = null): a
$stream = $file->fopen('rb');
}

$options = [
'timeout' => self::REMOTE_TIMEOUT_DEFAULT,
'multipart' => [
['name' => $file->getName(), 'contents' => $stream],
['name' => 'target', 'contents' => $target]
]
$options = RemoteOptionsService::getDefaultOptions(25);
$options['multipart'] = [
['name' => $file->getName(), 'contents' => $stream],
['name' => 'target', 'contents' => $target]
];

if ($this->appConfig->getDisableCertificateValidation()) {
Expand Down

0 comments on commit 1eda253

Please sign in to comment.