Don't set Content-Disposition header if one already exists
If a Content-Disposition header is already set by another plugin we don't need to set another one as this breaks clients. Fixes https://github.com/nextcloud/server/issues/1992 Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
This commit is contained in:
parent
e1b806467c
commit
8a00638425
4 changed files with 196 additions and 2 deletions
|
@ -247,8 +247,10 @@ class FilesPlugin extends ServerPlugin {
|
|||
$node = $this->tree->getNodeForPath($request->getPath());
|
||||
if (!($node instanceof IFile)) return;
|
||||
|
||||
// adds a 'Content-Disposition: attachment' header
|
||||
if ($this->downloadAttachment) {
|
||||
// adds a 'Content-Disposition: attachment' header in case no disposition
|
||||
// header has been set before
|
||||
if ($this->downloadAttachment &&
|
||||
$response->getHeader('Content-Disposition') === null) {
|
||||
$filename = $node->getName();
|
||||
if ($this->request->isUserAgent(
|
||||
[
|
||||
|
|
51
build/integration/data/bjoern.vcf
Normal file
51
build/integration/data/bjoern.vcf
Normal file
|
@ -0,0 +1,51 @@
|
|||
BEGIN:VCARD
|
||||
VERSION:3.0
|
||||
FN:Björn Schießle
|
||||
ORG:Nextcloud
|
||||
PHOTO;ENCODING=b;TYPE=jpeg:/9j/4AAQSkZJRgABAQEAbABrAAD//gA7Q1JFQVRPUjogZ2Qt
|
||||
anBlZyB2MS4wICh1c2luZyBJSkcgSlBFRyB2ODApLCBxdWFsaXR5ID0gOTAK/9sAQwAIBgYHBg
|
||||
UIBwcHCQkICgwUDQwLCwwZEhMPFB0aHx4dGhwcICQuJyAiLCMcHCg3KSwwMTQ0NB8nOT04Mjwu
|
||||
MzQy/9sAQwEJCQkMCwwYDQ0YMiEcITIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMj
|
||||
IyMjIyMjIyMjIyMjIyMjIy/8AAEQgAUABQAwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAA
|
||||
AAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZ
|
||||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dH9a63R5NSl8OC+sLnZMsrJOjfdkOchvyIFbRouMed9TrwlTlbS2PTdHvL3UoRcX0EdtHH91e
|
||||
mKFvIp2LW5DBjwR/OvPbO61zVP9Gnm2wE/MIyfmH17Vs3F0bRfscLD5Y8yFeijstVTpOrUUFuz
|
||||
rqV7RcuiJfFmnwan5j2xL3MNt5UZzwfm3Ej+VeZvI8ZWO6QvFjLAmvQIrtnkCocv3PpVPU9Btd
|
||||
ZhdXlkhlUYDof6V6uKynmjH2W6/E8GVZzk3I4O5tUtwxWKNV6fKB8wxu4H0qq6w+YeVKgDb2PT
|
||||
of8APatnWdGvdI08W8lsJ7QNv89QcD6+lZMhIsx5ezGMFum7HTFeLKnOk7SVmaRfUu+E/C9rqs
|
||||
0816kjBMc545rvLLS9O0yEpZ2kajplhktVfQrcWOiQ245cqGc+rMcmtnyfujHAr6TB4CnCKlNX
|
||||
b/AwqVHJnK3epfbPPh1e3W1to5/IinBzuOT2/rXTeCrWw/sK7h+2wuPNaUgcFUwMHB+lU9UsIb
|
||||
tkMwysfIUetUrfw9uguYrW6MCgbwjZO4/3R6VeJwvtY2ZpRr+zd0Xr3xB4d061doLx55scKqEf
|
||||
zxWRBqTatp4ZImg85zuJbJK9v60xPCyNLvmG7HQHnPua2rbTkhCqFGarDYKNGXMh1sTKorMW2i
|
||||
SCERxjFWIl2scd6kWLHT86MDn+6K7zmLUL/uyjqHVht2tzn2rmfEHw8stShMmmsLGflti58pj9
|
||||
P4fqPyrbhkLkv0UcCr8MxZCDXNXoRqL3kOM3F6H/2Q==
|
||||
UID:6454bec7-6f5b-46f2-ba22-15537ab215d9
|
||||
CATEGORIES:Engineering
|
||||
END:VCARD
|
|
@ -202,4 +202,115 @@ class CardDavContext implements \Behat\Behat\Context\Context {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given :user uploads the contact :fileName to the addressbook :addressbook
|
||||
*/
|
||||
public function uploadsTheContactToTheAddressbook($user, $fileName, $addressBook) {
|
||||
$davUrl = $this->baseUrl . '/remote.php/dav/addressbooks/users/'.$user.'/'.$addressBook . '/' . $fileName;
|
||||
$password = ($user === 'admin') ? 'admin' : '123456';
|
||||
|
||||
$request = $this->client->createRequest(
|
||||
'PUT',
|
||||
$davUrl,
|
||||
[
|
||||
'body' => file_get_contents(__DIR__ . '/../../data/' . $fileName),
|
||||
'auth' => [
|
||||
$user,
|
||||
$password,
|
||||
],
|
||||
'headers' => [
|
||||
'Content-Type' => 'application/xml;charset=UTF-8',
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
$this->response = $this->client->send($request);
|
||||
|
||||
if($this->response->getStatusCode() !== 201) {
|
||||
throw new \Exception(
|
||||
sprintf(
|
||||
'Expected %s got %s',
|
||||
201,
|
||||
$this->response->getStatusCode()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @When Exporting the picture of contact :fileName from addressbook :addressBook as user :user
|
||||
*/
|
||||
public function whenExportingThePictureOfContactFromAddressbookAsUser($fileName, $addressBook, $user) {
|
||||
$davUrl = $this->baseUrl . '/remote.php/dav/addressbooks/users/'.$user.'/'.$addressBook . '/' . $fileName . '?photo=true';
|
||||
$password = ($user === 'admin') ? 'admin' : '123456';
|
||||
|
||||
try {
|
||||
$request = $this->client->createRequest(
|
||||
'GET',
|
||||
$davUrl,
|
||||
[
|
||||
'auth' => [
|
||||
$user,
|
||||
$password,
|
||||
],
|
||||
'headers' => [
|
||||
'Content-Type' => 'application/xml;charset=UTF-8',
|
||||
],
|
||||
]
|
||||
);
|
||||
$this->response = $this->client->send($request);
|
||||
} catch (\GuzzleHttp\Exception\ClientException $e) {
|
||||
$this->response = $e->getResponse();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @When Downloading the contact :fileName from addressbook :addressBook as user :user
|
||||
*/
|
||||
public function whenDownloadingTheContactFromAddressbookAsUser($fileName, $addressBook, $user) {
|
||||
$davUrl = $this->baseUrl . '/remote.php/dav/addressbooks/users/'.$user.'/'.$addressBook . '/' . $fileName;
|
||||
$password = ($user === 'admin') ? 'admin' : '123456';
|
||||
|
||||
try {
|
||||
$request = $this->client->createRequest(
|
||||
'GET',
|
||||
$davUrl,
|
||||
[
|
||||
'auth' => [
|
||||
$user,
|
||||
$password,
|
||||
],
|
||||
'headers' => [
|
||||
'Content-Type' => 'application/xml;charset=UTF-8',
|
||||
],
|
||||
]
|
||||
);
|
||||
$this->response = $this->client->send($request);
|
||||
} catch (\GuzzleHttp\Exception\ClientException $e) {
|
||||
$this->response = $e->getResponse();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then The following HTTP headers should be set
|
||||
* @param \Behat\Gherkin\Node\TableNode $table
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function theFollowingHttpHeadersShouldBeSet(\Behat\Gherkin\Node\TableNode $table) {
|
||||
foreach($table->getTable() as $header) {
|
||||
$headerName = $header[0];
|
||||
$expectedHeaderValue = $header[1];
|
||||
$returnedHeader = $this->response->getHeader($headerName);
|
||||
if($returnedHeader !== $expectedHeaderValue) {
|
||||
throw new \Exception(
|
||||
sprintf(
|
||||
"Expected value '%s' for header '%s', got '%s'",
|
||||
$expectedHeaderValue,
|
||||
$headerName,
|
||||
$returnedHeader
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,3 +21,33 @@ Feature: carddav
|
|||
Scenario: Creating a new addressbook
|
||||
When "admin" creates an addressbook named "MyAddressbook" with statuscode "201"
|
||||
Then "admin" requests addressbook "admin/MyAddressbook" with statuscode "200"
|
||||
|
||||
Scenario: Accessing ones own contact
|
||||
Given "admin" creates an addressbook named "MyAddressbook" with statuscode "201"
|
||||
Given "admin" uploads the contact "bjoern.vcf" to the addressbook "MyAddressbook"
|
||||
When Downloading the contact "bjoern.vcf" from addressbook "MyAddressbook" as user "admin"
|
||||
Then The following HTTP headers should be set
|
||||
|Content-Disposition|attachment; filename*=UTF-8''bjoern.vcf; filename="bjoern.vcf"|
|
||||
|Content-Type|text/vcard; charset=utf-8|
|
||||
|Content-Security-Policy|default-src 'none';|
|
||||
|X-Content-Type-Options |nosniff|
|
||||
|X-Download-Options|noopen|
|
||||
|X-Frame-Options|Sameorigin|
|
||||
|X-Permitted-Cross-Domain-Policies|none|
|
||||
|X-Robots-Tag|none|
|
||||
|X-XSS-Protection|1; mode=block|
|
||||
|
||||
Scenario: Exporting the picture of ones own contact
|
||||
Given "admin" creates an addressbook named "MyAddressbook" with statuscode "201"
|
||||
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-Type|image/jpeg|
|
||||
|Content-Security-Policy|default-src 'none';|
|
||||
|X-Content-Type-Options |nosniff|
|
||||
|X-Download-Options|noopen|
|
||||
|X-Frame-Options|Sameorigin|
|
||||
|X-Permitted-Cross-Domain-Policies|none|
|
||||
|X-Robots-Tag|none|
|
||||
|X-XSS-Protection|1; mode=block|
|
||||
|
|
Loading…
Reference in a new issue