summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwebchick2013-03-29 17:27:03 (GMT)
committerwebchick2013-03-29 17:27:03 (GMT)
commitd35d390ffd72fd71a14cbd0af911e85b76b12096 (patch)
treeb9c554b7b75d6012a0543fb095401b2fd40595c5
parenta64d7b7db6ee304842d83ef0ffd643438d62f9da (diff)
Issue #1561362 by Niklas Fiekas, chrisdolby, mtift: Change file_transfer() to use BinaryFileResponse.
-rw-r--r--core/includes/file.inc26
-rw-r--r--core/lib/Drupal/Core/StreamWrapper/LocalStream.php16
-rw-r--r--core/modules/image/image.module4
-rw-r--r--core/modules/image/lib/Drupal/image/Tests/ImageStylesPathAndUrlTest.php2
-rw-r--r--core/modules/update/tests/modules/update_test/update_test.module8
5 files changed, 25 insertions, 31 deletions
diff --git a/core/includes/file.inc b/core/includes/file.inc
index 14c2850..ea41955 100644
--- a/core/includes/file.inc
+++ b/core/includes/file.inc
@@ -9,7 +9,7 @@ use Drupal\Core\StreamWrapper\LocalStream;
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..54e7e7a 100644
--- a/core/lib/Drupal/Core/StreamWrapper/LocalStream.php
+++ b/core/lib/Drupal/Core/StreamWrapper/LocalStream.php
@@ -339,6 +339,22 @@ abstract class LocalStream implements StreamWrapperInterface {
}
/**
+ * 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().
*
* @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..07ea3fb 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 @@ class ImageStylesPathAndUrlTest extends WebTestBase {
$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 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 @@
<?php
use Symfony\Component\HttpFoundation\Response;
-use Symfony\Component\HttpFoundation\StreamedResponse;
+use Symfony\Component\HttpFoundation\BinaryFileResponse;
/**
* @file
@@ -101,8 +101,8 @@ function update_test_update_status_alter(&$projects) {
* The project short name the update manager is trying to fetch data for (the
* fetch URLs are of the form: [base_url]/[project_name]/[core_version]).
*
- * @return StreamedResponse|Response
- * A StreamedResponse object containing the content of the XML release file
+ * @return BinaryFileResponse|Response
+ * A BinaryFileResponse object containing the content of the XML release file
* for the specified project if one is available; a Response object with no
* content otherwise.
*
@@ -132,7 +132,7 @@ function update_test_mock_page($project_name) {
// Return an empty response.
return new Response('', 200, $headers);
}
- return file_transfer($file, $headers);
+ return new BinaryFileResponse($file, 200, $headers);
}
/**