diff --git a/lib/Cake/Routing/Filter/AssetDispatcher.php b/lib/Cake/Routing/Filter/AssetDispatcher.php index 1e5d7a6fe..0c91c3cd7 100644 --- a/lib/Cake/Routing/Filter/AssetDispatcher.php +++ b/lib/Cake/Routing/Filter/AssetDispatcher.php @@ -1,7 +1,5 @@ data['request']->url); @@ -52,13 +51,19 @@ class AssetDispatcher extends DispatcherFilter { } $assetFile = $this->_getAssetFile($url); - if ($assetFile === null || !file_exists($assetFile)) { + if ($assetFile === null) { return null; } $response = $event->data['response']; $event->stopPropagation(); + if (!file_exists($assetFile)) { + $response->statusCode(404); + $response->send(); + return $response; + } + $response->modified(filemtime($assetFile)); if ($response->checkNotModified($event->data['request'])) { return $response; diff --git a/lib/Cake/Test/Case/Routing/Filter/AssetDispatcherTest.php b/lib/Cake/Test/Case/Routing/Filter/AssetDispatcherTest.php index 8fa069aa8..35c261cd8 100644 --- a/lib/Cake/Test/Case/Routing/Filter/AssetDispatcherTest.php +++ b/lib/Cake/Test/Case/Routing/Filter/AssetDispatcherTest.php @@ -129,6 +129,23 @@ class AssetDispatcherTest extends CakeTestCase { $this->assertEquals($time->format('D, j M Y H:i:s') . ' GMT', $response->modified()); } +/** + * Test 404 status code is set on missing asset. + * + * @return void + */ + public function test404OnMissingFile() { + $filter = new AssetDispatcher(); + + $response = $this->getMock('CakeResponse', array('_sendHeader')); + $request = new CakeRequest('/theme/test_theme/img/nope.gif'); + $event = new CakeEvent('Dispatcher.beforeRequest', $this, compact('request', 'response')); + + $response = $filter->beforeDispatch($event); + $this->assertTrue($event->isStopped()); + $this->assertEquals(404, $response->statusCode()); + } + /** * Test that no exceptions are thrown for //index.php type URLs. *