]> source.dussan.org Git - nextcloud-server.git/commitdiff
Change Content-Disposition Header 21945/head
authorJacob Neplokh <me@jacobneplokh.com>
Sat, 5 Sep 2020 18:44:01 +0000 (11:44 -0700)
committerJacob Neplokh <me@jacobneplokh.com>
Sat, 5 Sep 2020 18:46:25 +0000 (11:46 -0700)
- 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>
apps/dav/lib/CardDAV/ImageExportPlugin.php
apps/dav/lib/CardDAV/PhotoCache.php
apps/dav/tests/unit/CardDAV/ImageExportPluginTest.php
build/integration/features/carddav.feature

index 192c1e69ed13e6ebac4f4a5d2081fb3628bef9a6..fa4d5ea23f253a34191ba2556e9870c406ad0b93 100644 (file)
@@ -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());
index ca3853c76e687e5d5cd3f7a310173880bcfe8b3e..6ea999444af028a2252473db0f3b2e058d0234dc 100644 (file)
@@ -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',
index c3698a24a78625129f05fe6b59f2d6a9721290e7..c116a5ff7757da37f6f4555466d211886200a0f2 100644 (file)
@@ -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')
index 57fd8cd7da44f83c0c5f28848ad68ae6c1113633..16c165b6bab6743a071f0da8fc9c36cc4a3c1cbc 100644 (file)
@@ -55,7 +55,7 @@ Feature: carddav
     Given "admin" uploads the contact "bjoern.vcf" to the addressbook "MyAddressbook"
     When Exporting the picture of contact "bjoern.vcf" from addressbook "MyAddressbook" as user "admin"
     Then The following HTTP headers should be set
-      |Content-Disposition|attachment|
+      |Content-Disposition|attachment; filename=bjoern.vcf.jpg|
       |Content-Type|image/jpeg|
       |Content-Security-Policy|default-src 'none';|
       |X-Content-Type-Options |nosniff|