diff options
author | Vincent Petry <pvince81@owncloud.com> | 2016-06-15 15:27:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-15 15:27:36 +0200 |
commit | 3da5d06aa045ca01c8d38eaea02b3f63ae783648 (patch) | |
tree | 944c74c4159fa4e6dd1ec3acfdc7081e54c2bf9d /apps | |
parent | c5a60c3ae0a569215d7dc5fd27bd5ec8465bf0c3 (diff) | |
parent | 81761b87e4d29989329b398d4f797f0ccb47b144 (diff) | |
download | nextcloud-server-3da5d06aa045ca01c8d38eaea02b3f63ae783648.tar.gz nextcloud-server-3da5d06aa045ca01c8d38eaea02b3f63ae783648.zip |
Merge pull request #25052 from owncloud/stable9-webdav-download-mimetype
[stable9] DAV now returns file name with Content-Disposition header
Diffstat (limited to 'apps')
-rw-r--r-- | apps/dav/lib/connector/sabre/filesplugin.php | 29 | ||||
-rw-r--r-- | apps/dav/lib/connector/sabre/serverfactory.php | 6 | ||||
-rw-r--r-- | apps/dav/lib/server.php | 6 | ||||
-rw-r--r-- | apps/dav/tests/unit/connector/sabre/filesplugin.php | 13 | ||||
-rw-r--r-- | apps/dav/tests/unit/connector/sabre/filesreportplugin.php | 6 |
5 files changed, 51 insertions, 9 deletions
diff --git a/apps/dav/lib/connector/sabre/filesplugin.php b/apps/dav/lib/connector/sabre/filesplugin.php index bf9bee02578..857c98247bd 100644 --- a/apps/dav/lib/connector/sabre/filesplugin.php +++ b/apps/dav/lib/connector/sabre/filesplugin.php @@ -77,15 +77,25 @@ class FilesPlugin extends \Sabre\DAV\ServerPlugin { private $fileView; /** + * @var IRequest + */ + private $request; + + /** * @param \Sabre\DAV\Tree $tree * @param \OC\Files\View $view + * @param \OCP\IRequest $request * @param bool $isPublic */ - public function __construct(\Sabre\DAV\Tree $tree, - \OC\Files\View $view, - $isPublic = false) { + public function __construct( + \Sabre\DAV\Tree $tree, + \OC\Files\View $view, + \OCP\IRequest $request, + $isPublic = false + ) { $this->tree = $tree; $this->fileView = $view; + $this->request = $request; $this->isPublic = $isPublic; } @@ -193,7 +203,18 @@ class FilesPlugin extends \Sabre\DAV\ServerPlugin { if (!($node instanceof IFile)) return; // adds a 'Content-Disposition: attachment' header - $response->addHeader('Content-Disposition', 'attachment'); + $filename = $node->getName(); + if ($this->request->isUserAgent( + [ + \OC\AppFramework\Http\Request::USER_AGENT_IE, + \OC\AppFramework\Http\Request::USER_AGENT_ANDROID_MOBILE_CHROME, + \OC\AppFramework\Http\Request::USER_AGENT_FREEBOX, + ])) { + $response->addHeader('Content-Disposition', 'attachment; filename="' . rawurlencode($filename) . '"'); + } else { + $response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\'' . rawurlencode($filename) + . '; filename="' . rawurlencode($filename) . '"'); + } if ($node instanceof \OCA\DAV\Connector\Sabre\File) { //Add OC-Checksum header diff --git a/apps/dav/lib/connector/sabre/serverfactory.php b/apps/dav/lib/connector/sabre/serverfactory.php index c0b45c36a00..8462f624552 100644 --- a/apps/dav/lib/connector/sabre/serverfactory.php +++ b/apps/dav/lib/connector/sabre/serverfactory.php @@ -137,7 +137,11 @@ class ServerFactory { } $objectTree->init($root, $view, $this->mountManager); - $server->addPlugin(new \OCA\DAV\Connector\Sabre\FilesPlugin($objectTree, $view)); + $server->addPlugin(new \OCA\DAV\Connector\Sabre\FilesPlugin( + $objectTree, + $view, + $this->request + )); $server->addPlugin(new \OCA\DAV\Connector\Sabre\QuotaPlugin($view)); if($this->userSession->isLoggedIn()) { diff --git a/apps/dav/lib/server.php b/apps/dav/lib/server.php index 4711a80800d..791bd1ba7e8 100644 --- a/apps/dav/lib/server.php +++ b/apps/dav/lib/server.php @@ -125,7 +125,11 @@ class Server { $user = \OC::$server->getUserSession()->getUser(); if (!is_null($user)) { $view = \OC\Files\Filesystem::getView(); - $this->server->addPlugin(new FilesPlugin($this->server->tree, $view)); + $this->server->addPlugin(new FilesPlugin( + $this->server->tree, + $view, + $this->request + )); $this->server->addPlugin( new \Sabre\DAV\PropertyStorage\Plugin( diff --git a/apps/dav/tests/unit/connector/sabre/filesplugin.php b/apps/dav/tests/unit/connector/sabre/filesplugin.php index 0a790ec6fc9..ecad56d004d 100644 --- a/apps/dav/tests/unit/connector/sabre/filesplugin.php +++ b/apps/dav/tests/unit/connector/sabre/filesplugin.php @@ -72,8 +72,13 @@ class FilesPlugin extends \Test\TestCase { $this->view = $this->getMockBuilder('\OC\Files\View') ->disableOriginalConstructor() ->getMock(); + $request = $this->getMock('\OCP\IRequest'); - $this->plugin = new \OCA\DAV\Connector\Sabre\FilesPlugin($this->tree, $this->view); + $this->plugin = new \OCA\DAV\Connector\Sabre\FilesPlugin( + $this->tree, + $this->view, + $request + ); $this->plugin->initialize($this->server); } @@ -237,7 +242,11 @@ class FilesPlugin extends \Test\TestCase { } public function testGetPublicPermissions() { - $this->plugin = new \OCA\DAV\Connector\Sabre\FilesPlugin($this->tree, $this->view, true); + $this->plugin = new \OCA\DAV\Connector\Sabre\FilesPlugin( + $this->tree, + $this->view, + $this->getMock('\OCP\IRequest'), + true); $this->plugin->initialize($this->server); $propFind = new \Sabre\DAV\PropFind( diff --git a/apps/dav/tests/unit/connector/sabre/filesreportplugin.php b/apps/dav/tests/unit/connector/sabre/filesreportplugin.php index 87973ef0071..c17cc0f30a3 100644 --- a/apps/dav/tests/unit/connector/sabre/filesreportplugin.php +++ b/apps/dav/tests/unit/connector/sabre/filesreportplugin.php @@ -336,7 +336,11 @@ class FilesReportPlugin extends \Test\TestCase { ->method('getSize') ->will($this->returnValue(1024)); - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\FilesPlugin($this->tree, $this->view)); + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\FilesPlugin( + $this->tree, + $this->view, + $this->getMock('\OCP\IRequest') + )); $this->plugin->initialize($this->server); $responses = $this->plugin->prepareResponses($requestedProps, [$node1, $node2]); |