EllisLab/CodeIgniter — Issue #666: Output->set_content_type should also set charset.
Author: dazoe
Created: 2011-11-14 05:08:39+00:00
State: open

I was having some charset problems when using a controller to access css, so that i may minify it on the fly.
i was using $this->output->set_content_type('css') but it doesn't set the charset on the content-type header.
As a work around I used $this->output->set_content_type('text/css; charset=utf-8') which works.
A simple fix would be..

public function set_content_type($mime_type)
{
if (strpos($mime_type, '/') === FALSE)
{
$extension = ltrim($mime_type, '.');

// Is this extension supported?
if (isset($this->mime_types[$extension]))
{
$mime_type =& $this->mime_types[$extension];

if (is_array($mime_type))
{
$mime_type = current($mime_type);
}
}
}

$charset = config_item('charset');
if (($charset !== FALSE) AND ($charset != ''))
{
$charset = '; charset='.strtolower($charset);
}
else
{
$charset = '';
}
$header = 'Content-Type: '.$mime_type.$charset;

$this->headers[] = array($header, TRUE);

return $this;
}