Browse Source

Better assertions around content-transfer-encoding.

Mark Story 9 years ago
parent
commit
966cb034ed
2 changed files with 4 additions and 7 deletions
  1. 2 7
      src/Network/Response.php
  2. 2 0
      tests/TestCase/Network/ResponseTest.php

+ 2 - 7
src/Network/Response.php

@@ -2149,7 +2149,6 @@ class Response implements ResponseInterface
     public function withFile($path, array $options = [])
     {
         $file = $this->validateFile($path);
-
         $options += [
             'name' => null,
             'download' => null
@@ -2176,14 +2175,10 @@ class Response implements ResponseInterface
                 $contentType = 'application/force-download';
             }
 
-            if (!empty($contentType)) {
+            if (isset($contentType)) {
                 $new = $new->withType($contentType);
             }
-            if ($options['name'] === null) {
-                $name = $file->name;
-            } else {
-                $name = $options['name'];
-            }
+            $name = $options['name'] ?: $file->name;
             $new = $new->withDownload($name)
                 ->withHeader('Content-Transfer-Encoding', 'binary');
         }

+ 2 - 0
tests/TestCase/Network/ResponseTest.php

@@ -1680,6 +1680,7 @@ class ResponseTest extends TestCase
             $new->getHeaderLine('Content-Disposition')
         );
         $this->assertEquals('bytes', $new->getHeaderLine('Accept-Ranges'));
+        $this->assertEquals('binary', $new->getHeaderLine('Content-Transfer-Encoding'));
         $body = $new->getBody();
         $this->assertInstanceOf('Zend\Diactoros\Stream', $body);
 
@@ -2032,6 +2033,7 @@ class ResponseTest extends TestCase
             $new->getHeaderLine('Content-Type')
         );
         $this->assertFalse($new->hasHeader('Content-Disposition'));
+        $this->assertFalse($new->hasHeader('Content-Transfer-Encoding'));
     }
 
     /**