forked from ebhomengo/niki
1
0
Fork 0
niki/vendor/golang.org/x/net/http/httpguts/guts.go

88 lines
1.3 KiB
Go
Raw Normal View History

2024-02-18 10:42:21 +00:00
// Copyright 2018 The Go Authors. All rights reserved.
2024-02-18 10:42:21 +00:00
// Use of this source code is governed by a BSD-style
2024-02-18 10:42:21 +00:00
// license that can be found in the LICENSE file.
// Package httpguts provides functions implementing various details
2024-02-18 10:42:21 +00:00
// of the HTTP specification.
2024-02-18 10:42:21 +00:00
//
2024-02-18 10:42:21 +00:00
// This package is shared by the standard library (which vendors it)
2024-02-18 10:42:21 +00:00
// and x/net/http2. It comes with no API stability promise.
2024-02-18 10:42:21 +00:00
package httpguts
import (
"net/textproto"
"strings"
)
// ValidTrailerHeader reports whether name is a valid header field name to appear
2024-02-18 10:42:21 +00:00
// in trailers.
2024-02-18 10:42:21 +00:00
// See RFC 7230, Section 4.1.2
2024-02-18 10:42:21 +00:00
func ValidTrailerHeader(name string) bool {
2024-02-18 10:42:21 +00:00
name = textproto.CanonicalMIMEHeaderKey(name)
2024-02-18 10:42:21 +00:00
if strings.HasPrefix(name, "If-") || badTrailer[name] {
2024-02-18 10:42:21 +00:00
return false
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
return true
2024-02-18 10:42:21 +00:00
}
var badTrailer = map[string]bool{
"Authorization": true,
"Cache-Control": true,
"Connection": true,
"Content-Encoding": true,
"Content-Length": true,
"Content-Range": true,
"Content-Type": true,
"Expect": true,
"Host": true,
"Keep-Alive": true,
"Max-Forwards": true,
"Pragma": true,
"Proxy-Authenticate": true,
2024-02-18 10:42:21 +00:00
"Proxy-Authorization": true,
"Proxy-Connection": true,
"Range": true,
"Realm": true,
"Te": true,
"Trailer": true,
"Transfer-Encoding": true,
"Www-Authenticate": true,
2024-02-18 10:42:21 +00:00
}