diff --git a/core/includes/file.inc b/core/includes/file.inc index eaff634e2778..fa6670de0287 100644 --- a/core/includes/file.inc +++ b/core/includes/file.inc @@ -5,6 +5,9 @@ * API for handling file uploads and server file management. */ +use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; +use Symfony\Component\HttpFoundation\StreamedResponse; use Drupal\Core\StreamWrapper\LocalStream; /** @@ -2046,18 +2049,27 @@ function file_download() { $function = $module . '_file_download'; $result = $function($uri); if ($result == -1) { - return drupal_access_denied(); + throw new AccessDeniedHttpException(); } if (isset($result) && is_array($result)) { $headers = array_merge($headers, $result); } } if (count($headers)) { - file_transfer($uri, $headers); + return new StreamedResponse(function() use ($uri) { + $scheme = file_uri_scheme($uri); + // Transfer file in 1024 byte chunks to save memory usage. + if ($scheme && file_stream_wrapper_valid_scheme($scheme) && $fd = fopen($uri, 'rb')) { + while (!feof($fd)) { + print fread($fd, 1024); + } + fclose($fd); + } + }, 200, $headers); } - return drupal_access_denied(); + throw new AccessDeniedHttpException(); } - return drupal_not_found(); + throw new NotFoundHttpException(); } diff --git a/core/lib/Drupal/Core/UrlMatcher.php b/core/lib/Drupal/Core/UrlMatcher.php index 34ea187cccd9..2dd9d255c1ce 100644 --- a/core/lib/Drupal/Core/UrlMatcher.php +++ b/core/lib/Drupal/Core/UrlMatcher.php @@ -56,29 +56,22 @@ class UrlMatcher extends SymfonyUrlMatcher { } if ($router_item = $this->matchDrupalItem($dpathinfo)) { + $ret = $this->convertDrupalItem($router_item); + // Stash the router item in the attributes while we're transitioning. + $ret['drupal_menu_item'] = $router_item; - $routes = new RouteCollection(); - $routes->add(hash('sha256', $router_item['path']), $this->convertDrupalItem($router_item)); - - if ($ret = $this->matchCollection($pathinfo, $routes)) { - //drupal_set_message('
' . var_export('test', TRUE) . '
'); - // Stash the router item in the attributes while we're transitioning. - $ret['drupal_menu_item'] = $router_item; - - // Most legacy controllers (aka page callbacks) are in a separate file, - // so we have to include that. - if ($router_item['include_file']) { - require_once DRUPAL_ROOT . '/' . $router_item['include_file']; - } - - - return $ret; + // Most legacy controllers (aka page callbacks) are in a separate file, + // so we have to include that. + if ($router_item['include_file']) { + require_once DRUPAL_ROOT . '/' . $router_item['include_file']; } + + return $ret; } - throw 0 < count($this->allow) - ? new MethodNotAllowedException(array_unique(array_map('strtoupper', $this->allow))) - : new ResourceNotFoundException(); + // This matcher doesn't differentiate by method, so don't bother with those + // exceptions. + throw new ResourceNotFoundException(); } /** @@ -110,6 +103,7 @@ class UrlMatcher extends SymfonyUrlMatcher { foreach ($page_arguments as $k => $v) { $route[$k] = $v; } + return $route; return new Route($router_item['href'], $route); } } diff --git a/core/modules/simpletest/tests/file.test b/core/modules/simpletest/tests/file.test index c5eced152c1f..00bda2501542 100644 --- a/core/modules/simpletest/tests/file.test +++ b/core/modules/simpletest/tests/file.test @@ -2423,7 +2423,7 @@ class FileDownloadTest extends FileTestCase { $this->checkUrl('public', '', $basename, $base_url . '/' . file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath() . '/' . $basename_encoded); $this->checkUrl('private', '', $basename, $base_url . '/system/files/' . $basename_encoded); - $this->checkUrl('private', '', $basename, $base_url . '/?q=system/files/' . $basename_encoded, '0'); + $this->checkUrl('private', '', $basename, $base_url . '/index.php/system/files/' . $basename_encoded, '0'); } /**