From fcc16397b2c05d18b2bc89aedf668715d461cdad Mon Sep 17 00:00:00 2001 From: Robert Zondervan Date: Tue, 3 Dec 2024 09:55:17 +0100 Subject: [PATCH] Use the UrlGenerator instead of $_SERVER to determine address This gives a more reliable HTTP/HTTPS switch --- lib/Service/FileService.php | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/lib/Service/FileService.php b/lib/Service/FileService.php index ea608fc..7b8860c 100644 --- a/lib/Service/FileService.php +++ b/lib/Service/FileService.php @@ -14,6 +14,7 @@ use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; use OCP\IRequest; +use OCP\IURLGenerator; use OCP\IUserSession; use OCP\Lock\LockedException; use OCP\Share\IManager; @@ -37,7 +38,8 @@ public function __construct( private readonly IUserSession $userSession, private readonly LoggerInterface $logger, private readonly IRootFolder $rootFolder, - private readonly IManager $shareManager + private readonly IManager $shareManager, + private readonly IURLGenerator $urlGenerator, ) {} /** @@ -86,15 +88,7 @@ public function getShareLink(IShare $share): string */ private function getCurrentDomain(): string { - // Check if the request is over HTTPS - $isHttps = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'; - $protocol = $isHttps ? 'https://' : 'http://'; - - // Get the host (domain) - $host = $_SERVER['HTTP_HOST']; - - // Construct the full URL - return $protocol . $host; + return $this->urlGenerator->getBaseUrl(); } /**