Skip to content
Snippets Groups Projects
Unverified Commit e8a4feb1 authored by Jacob Neplokh's avatar Jacob Neplokh
Browse files

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: default avatarJacob Neplokh <me@jacobneplokh.com>
parent 62ab3eb7
No related branches found
No related tags found
No related merge requests found
......@@ -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());
......
......@@ -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',
......
......@@ -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')
......
......@@ -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|
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment