Skip to content
Permalink
Browse files

Don't mutate the response when setting a file.

type() is not a safe method in immutable contexts.
  • Loading branch information...
markstory committed Dec 9, 2016
1 parent 4cafa1e commit 2480c6b14d3018ae3508768abc151fe515a6ebe6
Showing with 11 additions and 2 deletions.
  1. +6 −2 src/Network/Response.php
  2. +5 −0 tests/TestCase/Network/ResponseTest.php
@@ -2155,12 +2155,16 @@ public function withFile($path, array $options = [])
'download' => null
];
$new = clone $this;
$extension = strtolower($file->ext());
if ((!$extension || $this->type($extension) === false) && $options['download'] === null) {
$mapped = $this->getMimeType($extension);
if ((!$extension || !$mapped) && $options['download'] === null) {
$options['download'] = true;
}
$new = clone $this;
if ($mapped) {
$new = $new->withType($extension);
}
$fileSize = $file->size();
if ($options['download']) {
@@ -1666,6 +1666,11 @@ public function testWithFileDownloadAndName()
'download' => true,
]
);
$this->assertEquals(
'text/html; charset=UTF-8',
$response->getHeaderLine('Content-Type'),
'No mutation'
);
$this->assertEquals(
'text/css; charset=UTF-8',
$new->getHeaderLine('Content-Type')

0 comments on commit 2480c6b

Please sign in to comment.
You can’t perform that action at this time.