Skip to content

Commit

Permalink
Adding the ability to compress the response sent from the MeviaView c…
Browse files Browse the repository at this point in the history
…lass
  • Loading branch information
lorenzo committed Oct 4, 2010
1 parent cf48ee7 commit bdade0f
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions cake/libs/view/media.php
Expand Up @@ -20,6 +20,12 @@
App::import('View', 'View', false);

class MediaView extends View {
/**
* Indicates whether response gzip compression was enabled for this class
*
* @var boolean
*/
private $compressionEnabled = false;

/**
* Constructor
Expand All @@ -42,7 +48,7 @@ function __construct(&$controller) {
* @return unknown
*/
function render() {
$name = $download = $extension = $id = $modified = $path = $size = $cache = $mimeType = null;
$name = $download = $extension = $id = $modified = $path = $size = $cache = $mimeType = $compress = null;
extract($this->viewVars, EXTR_OVERWRITE);

if ($size) {
Expand Down Expand Up @@ -135,7 +141,9 @@ function render() {
));
}
$this->_clearBuffer();
$this->_sendFile($handle);
if ($compress) {
$this->compressionEnabled = $this->response->compress();
}

$this->response->send();
return $this->_sendFile($handle);
Expand All @@ -155,7 +163,9 @@ protected function _sendFile($handle) {
set_time_limit(0);
$buffer = fread($handle, $chunkSize);
echo $buffer;
$this->_flushBuffer();
if (!$this->compressionEnabled) {
$this->_flushBuffer();
}
}
fclose($handle);
}
Expand Down

0 comments on commit bdade0f

Please sign in to comment.