Skip to content

Commit 0fd7a36

Browse files
committed
ACP2E-1627: [Cloud] Magento Product Recommendation/Data Services Causing File Download Warning
1 parent 8f0e217 commit 0fd7a36

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

lib/internal/Magento/Framework/App/Response/File.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ class File extends Http implements NotCacheableInterface
5454
'contentLength' => null,
5555
// Whether to remove the file after it is sent to the client
5656
'remove' => false,
57+
// Whether to send the file as attachment
58+
'attachment' => true
5759
];
5860

5961
/**
@@ -116,13 +118,15 @@ public function sendResponse()
116118
}
117119

118120
$this->response->setHttpResponseCode(200);
119-
$this->response->setHeader('Content-Type', $this->options['contentType'], $forceHeaders)
120-
->setHeader('Content-Length', $this->options['contentLength'], $forceHeaders)
121-
->setHeader(
121+
if ($this->options['attachment']) {
122+
$this->response->setHeader(
122123
'Content-Disposition',
123124
'attachment; filename="' . $this->options['fileName'] . '"',
124125
$forceHeaders
125-
)
126+
);
127+
}
128+
$this->response->setHeader('Content-Type', $this->options['contentType'], $forceHeaders)
129+
->setHeader('Content-Length', $this->options['contentLength'], $forceHeaders)
126130
->setHeader('Pragma', 'public', $forceHeaders)
127131
->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', $forceHeaders)
128132
->setHeader('Last-Modified', date('r'), $forceHeaders);
@@ -225,6 +229,7 @@ private function sendFileContent(): void
225229
*/
226230
private function afterFileIsSent(): void
227231
{
232+
$this->response->clearBody();
228233
if ($this->options['remove']) {
229234
$dir = $this->filesystem->getDirectoryWrite($this->options['directoryCode']);
230235
$dir->delete($this->options['filePath']);

lib/internal/Magento/Framework/App/Test/Unit/Response/FileTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ public function testSendResponseWithFilePath(): void
180180
$this->responseMock->expects($this->exactly(6))
181181
->method('setHeader')
182182
->withConsecutive(
183+
['Content-Disposition', 'attachment; filename="' . $fileName . '"', true],
183184
['Content-Type', $fileMimetype, true],
184185
['Content-Length', $fileSize, true],
185-
['Content-Disposition', 'attachment; filename="' . $fileName . '"', true],
186186
['Pragma', 'public', true],
187187
['Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true],
188188
[
@@ -255,9 +255,9 @@ public function testSendResponseWithRemoveOption(): void
255255
$this->responseMock->expects($this->exactly(6))
256256
->method('setHeader')
257257
->withConsecutive(
258+
['Content-Disposition', 'attachment; filename="' . $fileName . '"', true],
258259
['Content-Type', $fileMimetype, true],
259260
['Content-Length', $fileSize, true],
260-
['Content-Disposition', 'attachment; filename="' . $fileName . '"', true],
261261
['Pragma', 'public', true],
262262
['Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true],
263263
[
@@ -283,9 +283,9 @@ public function testSendResponseWithRawContent(): void
283283
$this->responseMock->expects($this->exactly(6))
284284
->method('setHeader')
285285
->withConsecutive(
286+
['Content-Disposition', 'attachment; filename="' . $fileName . '"', false],
286287
['Content-Type', $fileMimetype, false],
287288
['Content-Length', $fileSize, false],
288-
['Content-Disposition', 'attachment; filename="' . $fileName . '"', false],
289289
['Pragma', 'public', false],
290290
['Cache-Control', 'must-revalidate, post-check=0, pre-check=0', false],
291291
[

0 commit comments

Comments
 (0)