HTTP Header field is case-insensitive
goで http.Response からヘッダの値を取得する場合は以下のようになる code:header.go
func handler(w *http.ResponseWriter, r *http.Request) {
hval := r.Header.Get("Cache-Control")
}
チームでペアプロしていてgolang http.Request.Header.Get の仕様に踏み込んだがRFCでは case-insensitive なんだよねという話になり初耳だったので調べてみた
基本的にHeaderへのアクセサは大文字小文字を区別しない
// Get gets the first value associated with the given key.
// It is case insensitive; CanonicalMIMEHeaderKey is used
// to canonicalize the provided key.
とあるように case insensitive で[CanonicalMIMEHeaderKey]として正規化して取得する
HTTP においても Header (field) で規定されている
Each field line consists of a case-insensitive field name followed by a colon (":"), optional leading whitespace, the field line value, and optional trailing whitespace.
Appendix: