diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2016-02-10 14:35:50 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-02-10 14:35:50 +0100 |
commit | 159a0eb597425d7082aff7cf857d4d042cf8ebd2 (patch) | |
tree | cb8984fc217be9b05fcd5c6cdaf1672144262c08 | |
parent | c4d2f6bb25019ac2928ff123bc162d348cf1e941 (diff) | |
parent | 703f3551dc2c9caaebbcd2e9d9377f314dfd28ea (diff) | |
download | nextcloud-server-159a0eb597425d7082aff7cf857d4d042cf8ebd2.tar.gz nextcloud-server-159a0eb597425d7082aff7cf857d4d042cf8ebd2.zip |
Merge pull request #20073 from owncloud/files-should-add-download-disposition
Serve files with an attachment disposition for new DAV endpoint
-rw-r--r-- | apps/dav/lib/server.php | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/apps/dav/lib/server.php b/apps/dav/lib/server.php index 3bf8e155082..f5f1875a480 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,19 @@ 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) { + 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 $this->server->on('beforeMethod', function () { // custom properties plugin must be the last one |