diff options
author | Jacob Neplokh <me@jacobneplokh.com> | 2020-09-05 11:44:01 -0700 |
---|---|---|
committer | Jacob Neplokh <me@jacobneplokh.com> | 2020-09-05 11:46:25 -0700 |
commit | e8a4feb1c646f39ca83c72ae493095c3d37b9eb6 (patch) | |
tree | 1f2a21c8b07d01a4e680c28ca664d44ff0433eea /apps/dav | |
parent | 62ab3eb70016f57ced2dfccc7c095c3219c0cbf4 (diff) | |
download | nextcloud-server-e8a4feb1c646f39ca83c72ae493095c3d37b9eb6.tar.gz nextcloud-server-e8a4feb1c646f39ca83c72ae493095c3d37b9eb6.zip |
Change Content-Disposition Header
- Make ALLOWED_CONTENT_TYPES public in order to use
- Add $fileName variable which uses "$node->getName()" to get the proper file name and "$file->getMimeType()" along with the ALLOWED_CONTENT_TYPES array in PhotoCache.php to get the proper file extension
- Make "$fileName" the name of the file in the Content-Disposition header when downloading a Contact's photo
- Add filename to the CardDAV integration image export test header
- Change headers in ImageExportPluginTest to reflect changes
Signed-off-by: Jacob Neplokh <me@jacobneplokh.com>
Diffstat (limited to 'apps/dav')
-rw-r--r-- | apps/dav/lib/CardDAV/ImageExportPlugin.php | 3 | ||||
-rw-r--r-- | apps/dav/lib/CardDAV/PhotoCache.php | 2 | ||||
-rw-r--r-- | apps/dav/tests/unit/CardDAV/ImageExportPluginTest.php | 6 |
3 files changed, 6 insertions, 5 deletions
diff --git a/apps/dav/lib/CardDAV/ImageExportPlugin.php b/apps/dav/lib/CardDAV/ImageExportPlugin.php index 192c1e69ed1..fa4d5ea23f2 100644 --- a/apps/dav/lib/CardDAV/ImageExportPlugin.php +++ b/apps/dav/lib/CardDAV/ImageExportPlugin.php @@ -103,7 +103,8 @@ class ImageExportPlugin extends ServerPlugin { try { $file = $this->cache->get($addressbook->getResourceId(), $node->getName(), $size, $node); $response->setHeader('Content-Type', $file->getMimeType()); - $response->setHeader('Content-Disposition', 'attachment'); + $fileName = $node->getName() . '.' . PhotoCache::ALLOWED_CONTENT_TYPES[$file->getMimeType()]; + $response->setHeader('Content-Disposition', "attachment; filename=$fileName"); $response->setStatus(200); $response->setBody($file->getContent()); diff --git a/apps/dav/lib/CardDAV/PhotoCache.php b/apps/dav/lib/CardDAV/PhotoCache.php index ca3853c76e6..6ea999444af 100644 --- a/apps/dav/lib/CardDAV/PhotoCache.php +++ b/apps/dav/lib/CardDAV/PhotoCache.php @@ -43,7 +43,7 @@ use Sabre\VObject\Reader; class PhotoCache { /** @var array */ - protected const ALLOWED_CONTENT_TYPES = [ + public const ALLOWED_CONTENT_TYPES = [ 'image/png' => 'png', 'image/jpeg' => 'jpg', 'image/gif' => 'gif', diff --git a/apps/dav/tests/unit/CardDAV/ImageExportPluginTest.php b/apps/dav/tests/unit/CardDAV/ImageExportPluginTest.php index c3698a24a78..c116a5ff775 100644 --- a/apps/dav/tests/unit/CardDAV/ImageExportPluginTest.php +++ b/apps/dav/tests/unit/CardDAV/ImageExportPluginTest.php @@ -166,7 +166,7 @@ class ImageExportPluginTest extends TestCase { if ($photo) { $file = $this->createMock(ISimpleFile::class); $file->method('getMimeType') - ->willReturn('imgtype'); + ->willReturn('image/jpeg'); $file->method('getContent') ->willReturn('imgdata'); @@ -176,10 +176,10 @@ class ImageExportPluginTest extends TestCase { $this->response->expects($this->at(3)) ->method('setHeader') - ->with('Content-Type', 'imgtype'); + ->with('Content-Type', 'image/jpeg'); $this->response->expects($this->at(4)) ->method('setHeader') - ->with('Content-Disposition', 'attachment'); + ->with('Content-Disposition', 'attachment; filename=card.jpg'); $this->response->expects($this->once()) ->method('setStatus') |