From 2cad9d2b8c6ba38aa12e566fe7f2754e445368ea Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Tue, 27 Oct 2015 00:53:54 +0100 Subject: [PATCH 1/2] Serve files with an attachment disposition for new DAV endpoint This adds a `Content-Disposition: attachment` header to all files served via the DAV endpoint. --- apps/dav/lib/server.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/apps/dav/lib/server.php b/apps/dav/lib/server.php index 3bf8e15508..0c25890b66 100644 --- a/apps/dav/lib/server.php +++ b/apps/dav/lib/server.php @@ -30,6 +30,10 @@ use OCA\DAV\Files\CustomPropertiesBackend; use OCP\IRequest; use OCP\SabrePluginEvent; use Sabre\DAV\Auth\Plugin; +use Sabre\DAV\IFile; +use Sabre\HTTP\RequestInterface; +use Sabre\HTTP\ResponseInterface; +use Sabre\HTTP\Util; class Server { @@ -104,6 +108,14 @@ class Server { $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\FakeLockerPlugin()); } + // Serve all files with an Content-Disposition of type "attachment" + $this->server->on('beforeMethod', function (RequestInterface $requestInterface, ResponseInterface $responseInterface) { + $node = $this->server->tree->getNodeForPath($requestInterface->getPath()); + if (($node instanceof IFile)) { + $responseInterface->addHeader('Content-Disposition', 'attachment'); + } + }); + // wait with registering these until auth is handled and the filesystem is setup $this->server->on('beforeMethod', function () { // custom properties plugin must be the last one From 703f3551dc2c9caaebbcd2e9d9377f314dfd28ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Mon, 8 Feb 2016 17:49:25 +0100 Subject: [PATCH 2/2] Only set the header if the node exists and in case the request is a GET --- apps/dav/lib/server.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/apps/dav/lib/server.php b/apps/dav/lib/server.php index 0c25890b66..f5f1875a48 100644 --- a/apps/dav/lib/server.php +++ b/apps/dav/lib/server.php @@ -110,10 +110,15 @@ class Server { // Serve all files with an Content-Disposition of type "attachment" $this->server->on('beforeMethod', function (RequestInterface $requestInterface, ResponseInterface $responseInterface) { - $node = $this->server->tree->getNodeForPath($requestInterface->getPath()); - if (($node instanceof IFile)) { - $responseInterface->addHeader('Content-Disposition', 'attachment'); + if ($requestInterface->getMethod() === 'GET') { + $path = $requestInterface->getPath(); + if ($this->server->tree->nodeExists($path)) { + $node = $this->server->tree->getNodeForPath($path); + if (($node instanceof IFile)) { + $responseInterface->addHeader('Content-Disposition', 'attachment'); + } } + } }); // wait with registering these until auth is handled and the filesystem is setup