1. 程式人生 > >HTTP內容的大小寫問題

HTTP內容的大小寫問題

用curl模擬http請求大家都會,對於內容也都知道,但是問幾個問題
curl http://127.0.0.1/ -H “UA:Curl” -v和curl http://127.0.0.1/ -H “UA:curl” -v一樣嗎?
curl http://127.0.0.1/ -H “UA:Curl” -v和curl http://127.0.0.1/ -H “Ua:Curl” -v一樣嗎?
curl http://127.0.0.1/ -X POST -v和curl http://127.0.0.1/ -X post -v 一樣嗎?


可能就要猶豫了。今天正好翻了rfc,找到了答案。
RFC2616是最早的http1.0的規範,其中規定

  • Field names are case-insensitive,

現在rfc2616已經被rfc7230-7237取代,查看了這兩個RFC。

rfc7230中3.1.1. Request Line中明確說明:

  • The request method is case-sensitive.
  • Recipients of an invalid request-line SHOULD respond with either a 400 (Bad Request) error or a 301 (Moved Permanently) redirect with the request-target properly encoded. A recipient SHOULD NOT attempt to autocorrect and then process the request without a redirect, since the invalid request-line might be deliberately crafted to bypass security filters along the request chain.

上面意思是說請求行裡的請求方法是大小寫敏感的,,收到不認識的請求方法時,應該返回400或者301重定向,而不應該修改請求方法然後繼續處理。

rfc7231中4. Request Methods中說明

  • By convention, standardized methods are defined in all-uppercase US-ASCII letters.
  • All general-purpose servers MUST support the methods GET and HEAD. All other methods are OPTIONAL.

兩句意思是方法應該是全大寫ASCII字母,所有通用伺服器必須支援GET和head.其他方法是可選的。


現在知道開始問題的答案了吧