From 36d6b0f1e6eae58e20f35bb9d87671d338ea0a61 Mon Sep 17 00:00:00 2001 From: Git'Fellow <12234510+solracsf@users.noreply.github.com> Date: Sat, 14 Dec 2024 10:32:14 +0100 Subject: [PATCH] refactor: Use Http framework where possible Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com> --- .../lib/CalDAV/BirthdayCalendar/EnablePlugin.php | 7 ++++--- apps/dav/lib/CalDAV/Publishing/PublishPlugin.php | 5 +++-- apps/dav/lib/CalDAV/Search/SearchPlugin.php | 3 ++- apps/dav/lib/CardDAV/ImageExportPlugin.php | 7 ++++--- apps/dav/lib/CardDAV/MultiGetExportPlugin.php | 3 ++- apps/dav/lib/Comments/CommentsPlugin.php | 5 +++-- apps/dav/lib/Connector/Sabre/Auth.php | 15 ++++++--------- apps/dav/lib/Connector/Sabre/BearerAuth.php | 3 ++- .../lib/Connector/Sabre/ChecksumUpdatePlugin.php | 3 ++- .../Connector/Sabre/DummyGetResponsePlugin.php | 3 ++- apps/dav/lib/Connector/Sabre/FakeLockerPlugin.php | 12 +++++++----- .../dav/lib/Connector/Sabre/FilesReportPlugin.php | 3 ++- apps/dav/lib/DAV/Sharing/Plugin.php | 3 ++- .../Apple/AppleProvisioningPlugin.php | 11 ++++------- apps/dav/lib/SystemTag/SystemTagPlugin.php | 13 +++++++------ apps/dav/lib/Upload/ChunkingPlugin.php | 3 ++- apps/dav/lib/Upload/ChunkingV2Plugin.php | 5 +++-- 17 files changed, 57 insertions(+), 47 deletions(-) diff --git a/apps/dav/lib/CalDAV/BirthdayCalendar/EnablePlugin.php b/apps/dav/lib/CalDAV/BirthdayCalendar/EnablePlugin.php index b323673969bb2..cd0b58c53d2f2 100644 --- a/apps/dav/lib/CalDAV/BirthdayCalendar/EnablePlugin.php +++ b/apps/dav/lib/CalDAV/BirthdayCalendar/EnablePlugin.php @@ -7,6 +7,7 @@ use OCA\DAV\CalDAV\BirthdayService; use OCA\DAV\CalDAV\CalendarHome; +use OCP\AppFramework\Http; use OCP\IConfig; use OCP\IUser; use Sabre\DAV\Server; @@ -92,7 +93,7 @@ public function initialize(Server $server) { */ public function httpPost(RequestInterface $request, ResponseInterface $response) { $node = $this->server->tree->getNodeForPath($this->server->getRequestUri()); - if (!($node instanceof CalendarHome)) { + if (!$node instanceof CalendarHome) { return; } @@ -104,14 +105,14 @@ public function httpPost(RequestInterface $request, ResponseInterface $response) $owner = substr($node->getOwner(), 17); if ($owner !== $this->user->getUID()) { - $this->server->httpResponse->setStatus(403); + $this->server->httpResponse->setStatus(Http::STATUS_FORBIDDEN); return false; } $this->config->setUserValue($this->user->getUID(), 'dav', 'generateBirthdayCalendar', 'yes'); $this->birthdayService->syncUser($this->user->getUID()); - $this->server->httpResponse->setStatus(204); + $this->server->httpResponse->setStatus(Http::STATUS_NO_CONTENT); return false; } diff --git a/apps/dav/lib/CalDAV/Publishing/PublishPlugin.php b/apps/dav/lib/CalDAV/Publishing/PublishPlugin.php index 1916187af2b31..db73a761b0d26 100644 --- a/apps/dav/lib/CalDAV/Publishing/PublishPlugin.php +++ b/apps/dav/lib/CalDAV/Publishing/PublishPlugin.php @@ -7,6 +7,7 @@ use OCA\DAV\CalDAV\Calendar; use OCA\DAV\CalDAV\Publishing\Xml\Publisher; +use OCP\AppFramework\Http; use OCP\IConfig; use OCP\IURLGenerator; use Sabre\CalDAV\Xml\Property\AllowedSharingModes; @@ -179,7 +180,7 @@ public function httpPost(RequestInterface $request, ResponseInterface $response) $node->setPublishStatus(true); // iCloud sends back the 202, so we will too. - $response->setStatus(202); + $response->setStatus(Http::STATUS_ACCEPTED); // Adding this because sending a response body may cause issues, // and I wanted some type of indicator the response was handled. @@ -213,7 +214,7 @@ public function httpPost(RequestInterface $request, ResponseInterface $response) $node->setPublishStatus(false); - $response->setStatus(200); + $response->setStatus(Http::STATUS_OK); // Adding this because sending a response body may cause issues, // and I wanted some type of indicator the response was handled. diff --git a/apps/dav/lib/CalDAV/Search/SearchPlugin.php b/apps/dav/lib/CalDAV/Search/SearchPlugin.php index c69537523f299..602ce151e12f8 100644 --- a/apps/dav/lib/CalDAV/Search/SearchPlugin.php +++ b/apps/dav/lib/CalDAV/Search/SearchPlugin.php @@ -7,6 +7,7 @@ use OCA\DAV\CalDAV\CalendarHome; use OCA\DAV\CalDAV\Search\Xml\Request\CalendarSearchReport; +use OCP\AppFramework\Http; use Sabre\DAV\Server; use Sabre\DAV\ServerPlugin; @@ -133,7 +134,7 @@ private function calendarSearch($report) { $prefer = $this->server->getHTTPPrefer(); - $this->server->httpResponse->setStatus(207); + $this->server->httpResponse->setStatus(Http::STATUS_MULTI_STATUS); $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8'); $this->server->httpResponse->setHeader('Vary', 'Brief,Prefer'); diff --git a/apps/dav/lib/CardDAV/ImageExportPlugin.php b/apps/dav/lib/CardDAV/ImageExportPlugin.php index 8a950202c08fd..74a8b032e42fd 100644 --- a/apps/dav/lib/CardDAV/ImageExportPlugin.php +++ b/apps/dav/lib/CardDAV/ImageExportPlugin.php @@ -7,6 +7,7 @@ */ namespace OCA\DAV\CardDAV; +use OCP\AppFramework\Http; use OCP\Files\NotFoundException; use Sabre\CardDAV\Card; use Sabre\DAV\Server; @@ -59,7 +60,7 @@ public function httpGet(RequestInterface $request, ResponseInterface $response) $path = $request->getPath(); $node = $this->server->tree->getNodeForPath($path); - if (!($node instanceof Card)) { + if (!$node instanceof Card) { return true; } @@ -86,11 +87,11 @@ public function httpGet(RequestInterface $request, ResponseInterface $response) $response->setHeader('Content-Type', $file->getMimeType()); $fileName = $node->getName() . '.' . PhotoCache::ALLOWED_CONTENT_TYPES[$file->getMimeType()]; $response->setHeader('Content-Disposition', "attachment; filename=$fileName"); - $response->setStatus(200); + $response->setStatus(Http::STATUS_OK); $response->setBody($file->getContent()); } catch (NotFoundException $e) { - $response->setStatus(\OCP\AppFramework\Http::STATUS_NO_CONTENT); + $response->setStatus(Http::STATUS_NO_CONTENT); } return false; diff --git a/apps/dav/lib/CardDAV/MultiGetExportPlugin.php b/apps/dav/lib/CardDAV/MultiGetExportPlugin.php index 524ed4d433cd7..9d6b0df838e88 100644 --- a/apps/dav/lib/CardDAV/MultiGetExportPlugin.php +++ b/apps/dav/lib/CardDAV/MultiGetExportPlugin.php @@ -8,6 +8,7 @@ */ namespace OCA\DAV\CardDAV; +use OCP\AppFramework\Http; use Sabre\DAV; use Sabre\DAV\Server; use Sabre\HTTP\RequestInterface; @@ -65,7 +66,7 @@ public function httpReport(RequestInterface $request, ResponseInterface $respons $response->setHeader('Content-Disposition', 'attachment; filename="' . $filename . '"'); $response->setHeader('Content-Type', 'text/vcard'); - $response->setStatus(200); + $response->setStatus(Http::STATUS_OK); $response->setBody($output); return true; diff --git a/apps/dav/lib/Comments/CommentsPlugin.php b/apps/dav/lib/Comments/CommentsPlugin.php index 92ffae3f73e67..2ab7d6ee018db 100644 --- a/apps/dav/lib/Comments/CommentsPlugin.php +++ b/apps/dav/lib/Comments/CommentsPlugin.php @@ -7,6 +7,7 @@ */ namespace OCA\DAV\Comments; +use OCP\AppFramework\Http; use OCP\Comments\IComment; use OCP\Comments\ICommentsManager; use OCP\Comments\MessageTooLongException; @@ -108,7 +109,7 @@ public function httpPost(RequestInterface $request, ResponseInterface $response) $response->setHeader('Content-Location', $url); // created - $response->setStatus(201); + $response->setStatus(Http::STATUS_CREATED); return false; } @@ -177,7 +178,7 @@ public function onReport($reportName, $report, $uri) { new MultiStatus($responses) ); - $this->server->httpResponse->setStatus(207); + $this->server->httpResponse->setStatus(Http::STATUS_MULTI_STATUS); $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8'); $this->server->httpResponse->setBody($xml); diff --git a/apps/dav/lib/Connector/Sabre/Auth.php b/apps/dav/lib/Connector/Sabre/Auth.php index fa1c2e95fad1f..66c41262d54fe 100644 --- a/apps/dav/lib/Connector/Sabre/Auth.php +++ b/apps/dav/lib/Connector/Sabre/Auth.php @@ -13,6 +13,7 @@ use OC\User\Session; use OCA\DAV\Connector\Sabre\Exception\PasswordLoginForbidden; use OCA\DAV\Connector\Sabre\Exception\TooManyRequests; +use OCP\AppFramework\Http; use OCP\Defaults; use OCP\IRequest; use OCP\ISession; @@ -27,20 +28,16 @@ class Auth extends AbstractBasic { public const DAV_AUTHENTICATED = 'AUTHENTICATED_TO_DAV_BACKEND'; - private Session $userSession; private ?string $currentUser = null; - private Manager $twoFactorManager; public function __construct( private ISession $session, - Session $userSession, + private Session $userSession, private IRequest $request, - Manager $twoFactorManager, + private Manager $twoFactorManager, private IThrottler $throttler, string $principalPrefix = 'principals/users/', ) { - $this->userSession = $userSession; - $this->twoFactorManager = $twoFactorManager; $this->principalPrefix = $principalPrefix; // setup realm @@ -111,7 +108,7 @@ public function check(RequestInterface $request, ResponseInterface $response) { } catch (Exception $e) { $class = get_class($e); $msg = $e->getMessage(); - \OC::$server->get(LoggerInterface::class)->error($e->getMessage(), ['exception' => $e]); + \OCP\Server::get(LoggerInterface::class)->error($e->getMessage(), ['exception' => $e]); throw new ServiceUnavailable("$class: $msg"); } } @@ -166,7 +163,7 @@ private function auth(RequestInterface $request, ResponseInterface $response): a if ($this->request->getMethod() === 'POST') { $forcedLogout = true; } else { - $response->setStatus(401); + $response->setStatus(Http::STATUS_UNAUTHORIZED); throw new \Sabre\DAV\Exception\NotAuthenticated('CSRF check not passed.'); } } @@ -199,7 +196,7 @@ private function auth(RequestInterface $request, ResponseInterface $response): a } elseif (in_array('XMLHttpRequest', explode(',', $request->getHeader('X-Requested-With') ?? ''))) { // For ajax requests use dummy auth name to prevent browser popup in case of invalid creditials $response->addHeader('WWW-Authenticate', 'DummyBasic realm="' . $this->realm . '"'); - $response->setStatus(401); + $response->setStatus(Http::STATUS_UNAUTHORIZED); throw new \Sabre\DAV\Exception\NotAuthenticated('Cannot authenticate over ajax calls'); } return $data; diff --git a/apps/dav/lib/Connector/Sabre/BearerAuth.php b/apps/dav/lib/Connector/Sabre/BearerAuth.php index 1b85a9715534c..07bb3e052a5a0 100644 --- a/apps/dav/lib/Connector/Sabre/BearerAuth.php +++ b/apps/dav/lib/Connector/Sabre/BearerAuth.php @@ -5,6 +5,7 @@ */ namespace OCA\DAV\Connector\Sabre; +use OCP\AppFramework\Http; use OCP\Defaults; use OCP\IRequest; use OCP\ISession; @@ -56,6 +57,6 @@ public function validateBearerToken($bearerToken) { * @param ResponseInterface $response */ public function challenge(RequestInterface $request, ResponseInterface $response): void { - $response->setStatus(401); + $response->setStatus(Http::STATUS_UNAUTHORIZED); } } diff --git a/apps/dav/lib/Connector/Sabre/ChecksumUpdatePlugin.php b/apps/dav/lib/Connector/Sabre/ChecksumUpdatePlugin.php index 1bf45b22537f0..64a61a43a9b42 100644 --- a/apps/dav/lib/Connector/Sabre/ChecksumUpdatePlugin.php +++ b/apps/dav/lib/Connector/Sabre/ChecksumUpdatePlugin.php @@ -8,6 +8,7 @@ namespace OCA\DAV\Connector\Sabre; +use OCP\AppFramework\Http; use Sabre\DAV\Server; use Sabre\DAV\ServerPlugin; use Sabre\HTTP\RequestInterface; @@ -59,7 +60,7 @@ public function httpPatch(RequestInterface $request, ResponseInterface $response $node->setChecksum($checksum); $response->addHeader('OC-Checksum', $checksum); $response->setHeader('Content-Length', '0'); - $response->setStatus(204); + $response->setStatus(Http::STATUS_NO_CONTENT); return false; } diff --git a/apps/dav/lib/Connector/Sabre/DummyGetResponsePlugin.php b/apps/dav/lib/Connector/Sabre/DummyGetResponsePlugin.php index 26819836001ca..4a7e30caa100d 100644 --- a/apps/dav/lib/Connector/Sabre/DummyGetResponsePlugin.php +++ b/apps/dav/lib/Connector/Sabre/DummyGetResponsePlugin.php @@ -7,6 +7,7 @@ */ namespace OCA\DAV\Connector\Sabre; +use OCP\AppFramework\Http; use Sabre\DAV\Server; use Sabre\HTTP\RequestInterface; use Sabre\HTTP\ResponseInterface; @@ -48,7 +49,7 @@ public function httpGet(RequestInterface $request, ResponseInterface $response) fwrite($stream, $string); rewind($stream); - $response->setStatus(200); + $response->setStatus(Http::STATUS_OK); $response->setBody($stream); return false; diff --git a/apps/dav/lib/Connector/Sabre/FakeLockerPlugin.php b/apps/dav/lib/Connector/Sabre/FakeLockerPlugin.php index 485b6b09a3cde..61ecfaf845cce 100644 --- a/apps/dav/lib/Connector/Sabre/FakeLockerPlugin.php +++ b/apps/dav/lib/Connector/Sabre/FakeLockerPlugin.php @@ -7,9 +7,11 @@ */ namespace OCA\DAV\Connector\Sabre; +use OCP\AppFramework\Http; use Sabre\DAV\INode; use Sabre\DAV\Locks\LockInfo; use Sabre\DAV\PropFind; +use Sabre\DAV\Server; use Sabre\DAV\ServerPlugin; use Sabre\DAV\Xml\Property\LockDiscovery; use Sabre\DAV\Xml\Property\SupportedLock; @@ -29,11 +31,11 @@ * @package OCA\DAV\Connector\Sabre */ class FakeLockerPlugin extends ServerPlugin { - /** @var \Sabre\DAV\Server */ + /** @var Server */ private $server; /** {@inheritDoc} */ - public function initialize(\Sabre\DAV\Server $server) { + public function initialize(Server $server) { $this->server = $server; $this->server->on('method:LOCK', [$this, 'fakeLockProvider'], 1); $this->server->on('method:UNLOCK', [$this, 'fakeUnlockProvider'], 1); @@ -111,7 +113,7 @@ public function fakeLockProvider(RequestInterface $request, $lockInfo = new LockInfo(); $lockInfo->token = md5($request->getPath()); $lockInfo->uri = $request->getPath(); - $lockInfo->depth = \Sabre\DAV\Server::DEPTH_INFINITY; + $lockInfo->depth = Server::DEPTH_INFINITY; $lockInfo->timeout = 1800; $body = $this->server->xml->write('{DAV:}prop', [ @@ -119,7 +121,7 @@ public function fakeLockProvider(RequestInterface $request, new LockDiscovery([$lockInfo]) ]); - $response->setStatus(200); + $response->setStatus(Http::STATUS_OK); $response->setBody($body); return false; @@ -134,7 +136,7 @@ public function fakeLockProvider(RequestInterface $request, */ public function fakeUnlockProvider(RequestInterface $request, ResponseInterface $response) { - $response->setStatus(204); + $response->setStatus(Http::STATUS_NO_CONTENT); $response->setHeader('Content-Length', '0'); return false; } diff --git a/apps/dav/lib/Connector/Sabre/FilesReportPlugin.php b/apps/dav/lib/Connector/Sabre/FilesReportPlugin.php index c44dcc0d2da88..9e625ce3184e8 100644 --- a/apps/dav/lib/Connector/Sabre/FilesReportPlugin.php +++ b/apps/dav/lib/Connector/Sabre/FilesReportPlugin.php @@ -10,6 +10,7 @@ use OC\Files\View; use OCA\Circles\Api\v1\Circles; use OCP\App\IAppManager; +use OCP\AppFramework\Http; use OCP\Files\Folder; use OCP\Files\Node as INode; use OCP\IGroupManager; @@ -183,7 +184,7 @@ public function onReport($reportName, $report, $uri) { new MultiStatus($responses) ); - $this->server->httpResponse->setStatus(207); + $this->server->httpResponse->setStatus(Http::STATUS_MULTI_STATUS); $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8'); $this->server->httpResponse->setBody($xml); diff --git a/apps/dav/lib/DAV/Sharing/Plugin.php b/apps/dav/lib/DAV/Sharing/Plugin.php index cef8dc0b689d1..03e63813bab98 100644 --- a/apps/dav/lib/DAV/Sharing/Plugin.php +++ b/apps/dav/lib/DAV/Sharing/Plugin.php @@ -12,6 +12,7 @@ use OCA\DAV\Connector\Sabre\Auth; use OCA\DAV\DAV\Sharing\Xml\Invite; use OCA\DAV\DAV\Sharing\Xml\ShareRequest; +use OCP\AppFramework\Http; use OCP\IConfig; use OCP\IRequest; use Sabre\DAV\Exception\NotFound; @@ -157,7 +158,7 @@ public function httpPost(RequestInterface $request, ResponseInterface $response) $node->updateShares($message->set, $message->remove); - $response->setStatus(200); + $response->setStatus(Http::STATUS_OK); // Adding this because sending a response body may cause issues, // and I wanted some type of indicator the response was handled. $response->setHeader('X-Sabre-Status', 'everything-went-well'); diff --git a/apps/dav/lib/Provisioning/Apple/AppleProvisioningPlugin.php b/apps/dav/lib/Provisioning/Apple/AppleProvisioningPlugin.php index 36b08cd940cf8..be5831feee307 100644 --- a/apps/dav/lib/Provisioning/Apple/AppleProvisioningPlugin.php +++ b/apps/dav/lib/Provisioning/Apple/AppleProvisioningPlugin.php @@ -5,6 +5,7 @@ */ namespace OCA\DAV\Provisioning\Apple; +use OCP\AppFramework\Http; use OCP\IL10N; use OCP\IRequest; use OCP\IURLGenerator; @@ -66,7 +67,7 @@ public function httpGet(RequestInterface $request, ResponseInterface $response): $useSSL = ($serverProtocol === 'https'); if (!$useSSL) { - $response->setStatus(200); + $response->setStatus(Http::STATUS_OK); $response->setHeader('Content-Type', 'text/plain; charset=utf-8'); $response->setBody($this->l10n->t('Your %s needs to be configured to use HTTPS in order to use CalDAV and CardDAV with iOS/macOS.', [$this->themingDefaults->getName()])); @@ -75,11 +76,7 @@ public function httpGet(RequestInterface $request, ResponseInterface $response): $absoluteURL = $this->urlGenerator->getBaseUrl(); $parsedUrl = parse_url($absoluteURL); - if (isset($parsedUrl['port'])) { - $serverPort = $parsedUrl['port']; - } else { - $serverPort = 443; - } + $serverPort = $parsedUrl['port'] ?? 443; $server_url = $parsedUrl['host']; $description = $this->themingDefaults->getName(); @@ -128,7 +125,7 @@ public function httpGet(RequestInterface $request, ResponseInterface $response): ] )); - $response->setStatus(200); + $response->setStatus(Http::STATUS_OK); $response->setHeader('Content-Disposition', 'attachment; filename="' . $filename . '"'); $response->setHeader('Content-Type', 'application/xml; charset=utf-8'); $response->setBody($body); diff --git a/apps/dav/lib/SystemTag/SystemTagPlugin.php b/apps/dav/lib/SystemTag/SystemTagPlugin.php index e66be78c1a1cf..8305944cb0bcd 100644 --- a/apps/dav/lib/SystemTag/SystemTagPlugin.php +++ b/apps/dav/lib/SystemTag/SystemTagPlugin.php @@ -10,6 +10,7 @@ use OCA\DAV\Connector\Sabre\Directory; use OCA\DAV\Connector\Sabre\FilesPlugin; use OCA\DAV\Connector\Sabre\Node; +use OCP\AppFramework\Http; use OCP\IGroupManager; use OCP\IUser; use OCP\IUserSession; @@ -127,7 +128,7 @@ public function httpPost(RequestInterface $request, ResponseInterface $response) $response->setHeader('Content-Location', $url . $tag->getId()); // created - $response->setStatus(201); + $response->setStatus(Http::STATUS_CREATED); return false; } } @@ -209,7 +210,7 @@ public function handleGetProperties( return; } - if (!($node instanceof SystemTagNode) && !($node instanceof SystemTagMappingNode) && !($node instanceof SystemTagObjectType)) { + if (!$node instanceof SystemTagNode && !$node instanceof SystemTagMappingNode && !$node instanceof SystemTagObjectType) { return; } @@ -372,18 +373,18 @@ private function getTagsForFile(int $fileId, ?IUser $user): array { */ public function handleUpdateProperties($path, PropPatch $propPatch) { $node = $this->server->tree->getNodeForPath($path); - if (!($node instanceof SystemTagNode) && !($node instanceof SystemTagObjectType)) { + if (!$node instanceof SystemTagNode && !$node instanceof SystemTagObjectType) { return; } $propPatch->handle([self::OBJECTIDS_PROPERTYNAME], function ($props) use ($node) { - if (!($node instanceof SystemTagObjectType)) { + if (!$node instanceof SystemTagObjectType) { return false; } if (isset($props[self::OBJECTIDS_PROPERTYNAME])) { $propValue = $props[self::OBJECTIDS_PROPERTYNAME]; - if (!($propValue instanceof SystemTagsObjectList) || count($propValue->getObjects()) === 0) { + if (!$propValue instanceof SystemTagsObjectList || count($propValue->getObjects()) === 0) { throw new BadRequest('Invalid object-ids property'); } @@ -413,7 +414,7 @@ public function handleUpdateProperties($path, PropPatch $propPatch) { self::REFERENCE_FILEID_PROPERTYNAME, self::COLOR_PROPERTYNAME, ], function ($props) use ($node) { - if (!($node instanceof SystemTagNode)) { + if (!$node instanceof SystemTagNode) { return false; } diff --git a/apps/dav/lib/Upload/ChunkingPlugin.php b/apps/dav/lib/Upload/ChunkingPlugin.php index cf4d65168ccc9..8cc8f7d6c61f1 100644 --- a/apps/dav/lib/Upload/ChunkingPlugin.php +++ b/apps/dav/lib/Upload/ChunkingPlugin.php @@ -9,6 +9,7 @@ use OCA\DAV\Connector\Sabre\Directory; use OCA\DAV\Connector\Sabre\Exception\Forbidden; +use OCP\AppFramework\Http; use Sabre\DAV\Exception\BadRequest; use Sabre\DAV\Exception\NotFound; use Sabre\DAV\INode; @@ -89,7 +90,7 @@ public function performMove($path, $destination) { $response = $this->server->httpResponse; $response->setHeader('Content-Length', '0'); - $response->setStatus($fileExists ? 204 : 201); + $response->setStatus($fileExists ? Http::STATUS_NO_CONTENT : Http::STATUS_CREATED); return false; } diff --git a/apps/dav/lib/Upload/ChunkingV2Plugin.php b/apps/dav/lib/Upload/ChunkingV2Plugin.php index 846b4ea42ba40..07452dc0593ce 100644 --- a/apps/dav/lib/Upload/ChunkingV2Plugin.php +++ b/apps/dav/lib/Upload/ChunkingV2Plugin.php @@ -18,6 +18,7 @@ use OC_Hook; use OCA\DAV\Connector\Sabre\Directory; use OCA\DAV\Connector\Sabre\File; +use OCP\AppFramework\Http; use OCP\Files\IMimeTypeDetector; use OCP\Files\IRootFolder; use OCP\Files\ObjectStore\IObjectStoreMultiPartUpload; @@ -124,7 +125,7 @@ public function afterMkcol(RequestInterface $request, ResponseInterface $respons self::UPLOAD_TARGET_ID => $targetFile->getId(), ], 86400); - $response->setStatus(201); + $response->setStatus(Http::STATUS_CREATED); return true; } @@ -235,7 +236,7 @@ public function beforeMove($sourcePath, $destination): bool { $response = $this->server->httpResponse; $response->setHeader('Content-Type', 'application/xml; charset=utf-8'); $response->setHeader('Content-Length', '0'); - $response->setStatus($destinationExists ? 204 : 201); + $response->setStatus($destinationExists ? Http::STATUS_NO_CONTENT : Http::STATUS_CREATED); return false; }