Skip to content

Commit

Permalink
Setting a correct Content-Length for plugin assets
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Oct 29, 2011
1 parent 9866882 commit 60e3f02
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/Cake/Routing/Dispatcher.php
Expand Up @@ -315,6 +315,9 @@ protected function _deliverAsset(CakeResponse $response, $assetFile, $ext) {
}
$response->type($contentType);
}
if (!$compressionEnabled) {
$response->header('Content-Length', filesize($assetFile));
}
$response->cache(filemtime($assetFile));
$response->send();
ob_clean();
Expand Down
8 changes: 8 additions & 0 deletions lib/Cake/Test/Case/Routing/DispatcherTest.php
Expand Up @@ -1291,6 +1291,14 @@ public function testAssets() {
$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();
Expand Down

0 comments on commit 60e3f02

Please sign in to comment.