diff --git a/core/includes/file.inc b/core/includes/file.inc index 5f54190..4f8a770 100644 --- a/core/includes/file.inc +++ b/core/includes/file.inc @@ -9,7 +9,7 @@ use Drupal\Component\PhpStorage\MTimeProtectedFastFileStorage; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; -use Symfony\Component\HttpFoundation\StreamedResponse; +use Symfony\Component\HttpFoundation\BinaryFileResponse; /** * Stream wrapper bit flags that are the basis for composite types. @@ -1302,28 +1302,6 @@ function file_unmanaged_save_data($data, $destination = NULL, $replace = FILE_EX } /** - * Transfers a file to the client using HTTP. - * - * Pipes a file through Drupal to the client. - * - * @param $uri - * String specifying the file URI to transfer. - * @param $headers - * An array of HTTP headers to send along with file. - */ -function file_transfer($uri, $headers) { - return new StreamedResponse(function() use ($uri) { - // Transfer file in 1024 byte chunks to save memory usage. - if (file_exists($uri) && $fd = fopen($uri, 'rb')) { - while (!feof($fd)) { - print fread($fd, 1024); - } - fclose($fd); - } - }, 200, $headers); -} - -/** * Page callback: Handles private file transfers. * * Call modules that implement hook_file_download() to find out if a file is @@ -1351,7 +1329,7 @@ function file_download() { } } if (count($headers)) { - return file_transfer($uri, $headers); + return new BinaryFileResponse($uri, 200, $headers); } throw new AccessDeniedHttpException(); } diff --git a/core/lib/Drupal/Core/StreamWrapper/LocalStream.php b/core/lib/Drupal/Core/StreamWrapper/LocalStream.php index f84ecb1..c0f727c 100644 --- a/core/lib/Drupal/Core/StreamWrapper/LocalStream.php +++ b/core/lib/Drupal/Core/StreamWrapper/LocalStream.php @@ -339,6 +339,24 @@ public function stream_close() { } /** + * Signal that stream_select is not supported by returning false. + * + * Fixes warnings messages like this: + * finfo::file() [finfo.file]: Drupal\Core\StreamWrapper\PrivateStream::stream_cast is not implemented! + * + * @param int + * Can be STREAM_CAST_FOR_SELECT or STREAM_CAST_AS_STREAM + * + * @return bool false + * + * @see http://drupal.org/node/1561362 + * @see: http://php.net/manual/en/streamwrapper.stream-cast.php + */ + public function stream_cast(int $cast_as) { + return false; + } + + /** * Support for unlink(). * * @param string $uri diff --git a/core/modules/image/image.module b/core/modules/image/image.module index b2816de..7be1abd 100644 --- a/core/modules/image/image.module +++ b/core/modules/image/image.module @@ -6,7 +6,7 @@ */ use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpFoundation\StreamedResponse; +use Symfony\Component\HttpFoundation\BinaryFileResponse; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Drupal\Component\Uuid\Uuid; use Drupal\file\Plugin\Core\Entity\File; @@ -669,7 +669,7 @@ function image_style_deliver($style, $scheme) { 'Content-Type' => $image->info['mime_type'], 'Content-Length' => $image->info['file_size'], ); - return file_transfer($uri, $headers); + return new BinaryFileResponse($uri, 200, $headers); } else { watchdog('image', 'Unable to generate the derived image located at %path.', array('%path' => $derivative_uri)); diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageStylesPathAndUrlTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageStylesPathAndUrlTest.php index f755ba0..987be11 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageStylesPathAndUrlTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageStylesPathAndUrlTest.php @@ -150,7 +150,8 @@ function _testImageStyleUrlAndPath($scheme, $clean_url = TRUE, $extra_slash = FA $this->assertEqual($this->drupalGetHeader('Content-Length'), $generated_image_info['file_size'], 'Expected Content-Length was reported.'); if ($scheme == 'private') { $this->assertEqual($this->drupalGetHeader('Expires'), 'Sun, 19 Nov 1978 05:00:00 GMT', 'Expires header was sent.'); - $this->assertEqual($this->drupalGetHeader('Cache-Control'), 'no-cache, private', 'Cache-Control header was set to prevent caching.'); + // Checking that the 'Cache-Control' header contains 'no-cache' + $this->assertNotEqual(strpos($this->drupalGetHeader('Cache-Control'), 'no-cache'), FALSE, 'Cache-Control header was set to prevent caching.'); $this->assertEqual($this->drupalGetHeader('X-Image-Owned-By'), 'image_module_test', 'Expected custom header has been added.'); // Make sure that a second request to the already existing derivate works diff --git a/core/modules/update/tests/modules/update_test/update_test.module b/core/modules/update/tests/modules/update_test/update_test.module index 1f88fe9..edc7aa4 100644 --- a/core/modules/update/tests/modules/update_test/update_test.module +++ b/core/modules/update/tests/modules/update_test/update_test.module @@ -1,7 +1,7 @@