diff --git a/core/includes/file.inc b/core/includes/file.inc index 14c285077e106b35c9996a1c5598a03ac6387b12..ea41955d6a59408af59f1e7bf165209b008dedc4 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. @@ -1301,28 +1301,6 @@ function file_unmanaged_save_data($data, $destination = NULL, $replace = FILE_EX return file_unmanaged_move($temp_name, $destination, $replace); } -/** - * 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. * @@ -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 f84ecb17e321497108119d059c01b791b4ad1027..54e7e7a7a3a85d08a02e5690c8b5f1143d9211c2 100644 --- a/core/lib/Drupal/Core/StreamWrapper/LocalStream.php +++ b/core/lib/Drupal/Core/StreamWrapper/LocalStream.php @@ -338,6 +338,22 @@ public function stream_close() { return fclose($this->handle); } + /** + * Gets the underlying stream resource for stream_select(). + * + * @param int $cast_as + * Can be STREAM_CAST_FOR_SELECT or STREAM_CAST_AS_STREAM. + * + * @return resource|false + * The underlying stream resource or FALSE if stream_select() is not + * supported. + * + * @see http://php.net/manual/streamwrapper.stream-cast.php + */ + public function stream_cast($cast_as) { + return false; + } + /** * Support for unlink(). * diff --git a/core/modules/image/image.module b/core/modules/image/image.module index b2816de0ff0449297acad449a4a40948ba80aa4a..7be1abd27516f798b8c95489abdc4446f3383573 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 f755ba0dfbd502fa0f73bf9a24339a5b9fae410f..07ea3fbb40bdf24d9a4cd92a5d802e9d2fbe2f16 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageStylesPathAndUrlTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageStylesPathAndUrlTest.php @@ -150,7 +150,7 @@ 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.'); + $this->assertNotEqual(strpos($this->drupalGetHeader('Cache-Control'), 'no-cache'), FALSE, 'Cache-Control header contains \'no-cache\' 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 1f88fe96beb89e9f52109c3c1bc0f50e2bdd2b32..edc7aa4270fa5fa9722123ff9f208208943afdb4 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 @@