1

I would like to send the header "X-Content-Type-Options: nosniff" back with every response in my zend framework 2 application. How can I do that without explicitly coding it in every single controller method?

4

1 回答 1

8

您可以通过引导程序修改响应对象:

模块.php

/**
 * On bootstrap event
 * 
 * @param \Zend\Mvc\MvcEvent $e
 */
public function onBootstrap(MvcEvent $e)
{
    $headers = $e->getResponse()->getHeaders(); 
    $headers->addHeaderLine('X-Content-Type-Options: nosniff');
}
于 2013-04-25T13:28:23.243 回答