Skip to content
Permalink
Browse files

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.
  • Loading branch information...
markstory committed Apr 14, 2014
1 parent 749f2b9 commit f1b57d14ab20d779727f7c021ce1d1c18667823d
@@ -51,31 +51,20 @@ public function beforeDispatch(CakeEvent $event) {
}
$assetFile = $this->_getAssetFile($url);
if ($assetFile === null) {
if ($assetFile === null || !file_exists($assetFile)) {
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'];
$event->stopPropagation();
if (!$isFile) {
$response->statusCode(404);
$response->send();
return $response;
}
$response->modified(filemtime($assetFile));
if ($response->checkNotModified($event->data['request'])) {
return $response;
}
$pathSegments = explode('.', $url);
$ext = array_pop($pathSegments);
$this->_deliverAsset($response, $assetFile, $ext);
return $response;
}
@@ -108,11 +108,6 @@ public function testNoHandleRoutedExtension() {
$event = new CakeEvent('DispatcherTest', $this, compact('request', 'response'));
$this->assertNull($filter->beforeDispatch($event));
$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 @@ public function testNotModified() {
$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.
*

0 comments on commit f1b57d1

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.