Skip to content

Commit

Permalink
Move content-type setting to controller plugin.
Browse files Browse the repository at this point in the history
This tries harder to avoid any duplicate setting of the content-type
header, which breaks fastcgi setups.
  • Loading branch information
zerocrates committed Mar 13, 2013
1 parent 842bf1e commit 4ccdb3d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
Expand Up @@ -52,6 +52,9 @@ public function init()
$front->registerPlugin(
new Omeka_Controller_Plugin_Ssl((string)$sslConfig, $redirector, $auth));
}

// Add a default content-type fallback.
$front->registerPlugin(new Omeka_Controller_Plugin_DefaultContentType);

return $front;
}
Expand Down
Expand Up @@ -50,7 +50,6 @@ public function __construct(Zend_Controller_Request_Abstract $request,
array $invokeArgs = array()
) {
parent::__construct($request, $response, $invokeArgs);
$response->setHeader('Content-Type', 'text/html; charset=utf-8', true);
$this->_setActionContexts();
}

Expand Down
@@ -0,0 +1,38 @@
<?php
/**
* Omeka
*
* @copyright Copyright 2007-2012 Roy Rosenzweig Center for History and New Media
* @license http://www.gnu.org/licenses/gpl-3.0.txt GNU GPLv3
*/

/**
* This controller plugin sets the default Content-Type header when one hasn't
* been set at the end of the controller processing.
*
* This has to be done here because Zend allows header duplication, the
* output contexts don't overwrite headers of the same name, and some servers
* (FastCGI) choke when they see two Content-Type headers.
*/
class Omeka_Controller_Plugin_DefaultContentType extends Zend_Controller_Plugin_Abstract
{
/**
* Add a default Content-Type to the response if none is already set.
*/
public function dispatchLoopShutdown()
{
$response = $this->getResponse();

$typeAlreadySet = false;
foreach ($response->getHeaders() as $header) {
if ($header['name'] == 'Content-Type') {
$typeAlreadySet = true;
break;
}
}

if (!$typeAlreadySet) {
$response->setHeader('Content-Type', 'text/html; charset=utf-8');
}
}
}

0 comments on commit 4ccdb3d

Please sign in to comment.