diff options
author | Lukas Reschke <lukas@owncloud.com> | 2015-10-27 00:53:54 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-02-08 17:08:34 +0100 |
commit | 2cad9d2b8c6ba38aa12e566fe7f2754e445368ea (patch) | |
tree | e8dc2b39b8a5f6285e7d53fc8485e913580478e1 | |
parent | a35d5625e0ff3e50ab18b4079c630837e8322ffd (diff) | |
download | nextcloud-server-2cad9d2b8c6ba38aa12e566fe7f2754e445368ea.tar.gz nextcloud-server-2cad9d2b8c6ba38aa12e566fe7f2754e445368ea.zip |
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.
-rw-r--r-- | apps/dav/lib/server.php | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/apps/dav/lib/server.php b/apps/dav/lib/server.php index 3bf8e155082..0c25890b662 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 |