Setting a correct Content-Length for plugin assets

This commit is contained in:
Jose Lorenzo Rodriguez 2011-10-28 23:45:31 -04:30
parent 9866882506
commit 60e3f02eac
2 changed files with 11 additions and 0 deletions

View file

@ -315,6 +315,9 @@ class Dispatcher {
}
$response->type($contentType);
}
if (!$compressionEnabled) {
$response->header('Content-Length', filesize($assetFile));
}
$response->cache(filemtime($assetFile));
$response->send();
ob_clean();

View file

@ -1291,6 +1291,14 @@ class DispatcherTest extends CakeTestCase {
$result = ob_get_clean();
$this->assertEqual('htc file', $result);
$response = $this->getMock('CakeResponse', array('_sendHeader'));
ob_start();
$Dispatcher->asset('test_plugin/css/unknown.extension', $response);
ob_end_clean();
$expected = filesize(CakePlugin::path('TestPlugin') . 'webroot' . DS . 'css' . DS . 'unknown.extension');
$headers = $response->header();
$this->assertEqual($expected, $headers['Content-Length']);
if (php_sapi_name() == 'cli') {
while (ob_get_level()) {
ob_get_clean();