2013-04-14 149 views
3

我在Zend Framework(1)中遇到了一个应用程序问题。在zend中删除http响应标头

在一个特定的动作我尝试删除一些信息,但是在响应我仍然收到这些头:

$this->getResponse->clearAllHeaders() 
         ->clearRawHeaders(); 
    $this->getResponse->setHeader('A-Header', 'headervalue'); 

我期待的回应是:

HTTP/1.1 XXX Some HTTP status code 
    A-Header: headervalue 

却是:

HTTP/1.1 XXX Some HTTP status code 
    Date: Sun, 14 Apr 2013 16:26:59 GMT 
    Server: Apache/2.2.16 (Debian) 
    X-Powered-By: PHP/5.3.3-7+squeeze15 
    Vary: Accept-Encoding 
    Content-Length: 0 
    Content-Type: text/html 

如何删除Date,Server,X-Powered-By,Vary,Content-Lenght,Content-Type?至少Content *标头。

谢谢

+0

在其应用程序的一部分,你清楚吗? – zavg

+0

嗨zavg。我试图在几个方面做到这一点 - 在一个特定的行动,在postDispatch钩子,在dispatchLoopShutdown挂钩。但没有成功... – Artur

+0

你为什么想这样做?除了X-Powered-By之外,这些标题每个都有其用途。 –

回答

7

这些头文件由Apache追加。

您可以使用mod_headers来虽然控制其行为:

http://httpd.apache.org/docs/2.2/mod/mod_headers.html

例子:

<IfModule mod_headers.c> 
    Header unset Server 
    Header unset X-Powered-By 
</IfModule> 
+0

好的,谢谢你。但是Content *标题怎么样? – Artur

+2

你将需要'mod_mime'并使用'RemoveType'指令。但我不确定它会让你脱离日期和内容长度,因为这些是HTTP标准所要求的。 – haim770

+2

还要确保你使用'ServerSignature Off'和'SeverTokens Prod'。 – haim770