Revert changed added in #2750.

While the had the potential to make 404s going through AssetDispatcher
much faster, they broke plugins + extension routing. While explicit
extensions could be fixed, routing all extensions could not. Because we
are trying to keep 2.x as API compatible as possible it makes sense to
revert the previous changes.
This commit is contained in:
mark_story 2014-04-13 20:00:34 -04:00
parent 749f2b99d9
commit f1b57d14ab
2 changed files with 4 additions and 37 deletions

View file

@ -51,31 +51,20 @@ class AssetDispatcher extends DispatcherFilter {
} }
$assetFile = $this->_getAssetFile($url); $assetFile = $this->_getAssetFile($url);
if ($assetFile === null) { if ($assetFile === null || !file_exists($assetFile)) {
return null; return null;
} }
$pathSegments = explode('.', $url);
$ext = array_pop($pathSegments);
$isFile = file_exists($assetFile);
if (in_array($ext, Router::extensions()) && !$isFile) {
return null;
}
$response = $event->data['response']; $response = $event->data['response'];
$event->stopPropagation(); $event->stopPropagation();
if (!$isFile) {
$response->statusCode(404);
$response->send();
return $response;
}
$response->modified(filemtime($assetFile)); $response->modified(filemtime($assetFile));
if ($response->checkNotModified($event->data['request'])) { if ($response->checkNotModified($event->data['request'])) {
return $response; return $response;
} }
$pathSegments = explode('.', $url);
$ext = array_pop($pathSegments);
$this->_deliverAsset($response, $assetFile, $ext); $this->_deliverAsset($response, $assetFile, $ext);
return $response; return $response;
} }

View file

@ -108,11 +108,6 @@ class AssetDispatcherTest extends CakeTestCase {
$event = new CakeEvent('DispatcherTest', $this, compact('request', 'response')); $event = new CakeEvent('DispatcherTest', $this, compact('request', 'response'));
$this->assertNull($filter->beforeDispatch($event)); $this->assertNull($filter->beforeDispatch($event));
$this->assertFalse($event->isStopped(), 'Events for routed extensions should not be stopped'); $this->assertFalse($event->isStopped(), 'Events for routed extensions should not be stopped');
$request = new CakeRequest('test_plugin/api/v1/forwarding.png');
$event = new CakeEvent('DispatcherTest', $this, compact('request', 'response'));
$this->assertSame($response, $filter->beforeDispatch($event));
$this->assertTrue($event->isStopped());
} }
/** /**
@ -161,23 +156,6 @@ class AssetDispatcherTest extends CakeTestCase {
$this->assertEquals($time->format('D, j M Y H:i:s') . ' GMT', $response->modified()); $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. * Test that no exceptions are thrown for //index.php type URLs.
* *