2013-01-17 91 views
1

我開始正確學習http了。HTTP頭自動設置

我正在燈堆棧中工作。

在命令行上,我要求一個本地頁面,它將與apache一起提供,以查看返回的標題。

curl -i local.testsite 

我請求的頁面沒有內容,我沒有設置任何信息,但是目前已經有響應,如發送大量的頭:

HTTP/1.1 200 OK 
Date: Thu, 17 Jan 2013 20:28:52 GMT 
Server: Apache/2.2.22 (Ubuntu) 
X-Powered-By: PHP/5.3.10-1ubuntu3.4 
Vary: Accept-Encoding 
Content-Length: 0 
Content-Type: text/html 

所以,如果我沒有設置這些,阿帕奇自動設置這些?

+6

簡答......是的。 – Leeish

+0

是的,Apache會自動設置它們。你可以設置'Server:'和'X-Powered-By:'不是默認的。 –

回答

3

有些是由PHP設置:

  • X-Powered-By頭由expose_php INI設置設定。
  • Content-Type標頭由default_mimetype INI設置設置。

其餘是由Apache的設置:

  • Server頭由ServerSignature指令集。
  • 當啓用mod_deflate時,通常會發送Vary: Accept-Encoding標頭。

DateContent-Length不可配置,因爲它們是HTTP規範的一部分。 Dateincluded as a MUST(某些條件除外)和Content-Lengthas a SHOULD。請參閱How to remove date header from apache?How to disable the Content-Length response header with Apache?

3

是的,Apache默認設置這些。順便說一句,如果你只關心標題,你應該使用

curl -I local.testsite 

-I返回頭只(HTTP HEAD請求),這樣,即使你在頁面上有內容,你將只能得到頭。