2013-04-14 147 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