Documentation ¶
Overview ¶
Package headers is all about HTTP header names.
Index ¶
- Constants
- Variables
- func First(hdrs http.Header, k string) (string, []string, bool)
- func IsForbiddenRequestHeaderName(name string) bool
- func IsForbiddenResponseHeaderName(name string) bool
- func IsProhibitedRequestHeaderName(name string) bool
- func IsProhibitedResponseHeaderName(name string) bool
- func IsSafelistedResponseHeaderName(name string) bool
- func IsValid(name string) bool
- type SortedSet
Constants ¶
const ( // common request headers Origin = "Origin" // preflight-only request headers ACRPN = "Access-Control-Request-Private-Network" ACRM = "Access-Control-Request-Method" ACRH = "Access-Control-Request-Headers" // common response headers ACAO = "Access-Control-Allow-Origin" ACAC = "Access-Control-Allow-Credentials" // preflight-only response headers ACAPN = "Access-Control-Allow-Private-Network" ACAM = "Access-Control-Allow-Methods" ACAH = "Access-Control-Allow-Headers" ACMA = "Access-Control-Max-Age" // actual-only response headers ACEH = "Access-Control-Expose-Headers" Vary = "Vary" )
header names in canonical format
const ( ValueTrue = "true" ValueWildcard = "*" ValueVaryOptions = ACRH + ", " + ACRM + ", " + ACRPN + ", " + Origin )
const Authorization = "authorization" // note: byte-lowercase
const ValueSep = ","
Variables ¶
var ( PreflightVarySgl = []string{ValueVaryOptions} TrueSgl = []string{ValueTrue} OriginSgl = []string{Origin} WildcardSgl = []string{ValueWildcard} WildcardAuthSgl = []string{ValueWildcard + ValueSep + Authorization} )
Functions ¶
func First ¶
First, if k is present in hdrs, returns the value associated to k in hdrs, a singleton slice containing that value, and true; otherwise, First returns "", nil, false. Precondition: k is in canonical format (see http.CanonicalHeaderKey).
First is useful because
- contrary to http.Header.Get, it returns a slice that can be reused, which saves a heap allocation in client code;
- it returns the value both as a scalar and as a singleton slice, which saves a bounds check in client code.
func IsForbiddenRequestHeaderName ¶
IsForbiddenRequestHeaderName reports whether name is a forbidden request-header name per the Fetch standard.
Precondition: name is a valid and byte-lowercase header name.
func IsForbiddenResponseHeaderName ¶
IsForbiddenResponseHeaderName reports whether name is a forbidden response-header name per the Fetch standard.
Precondition: name is a valid and byte-lowercase header name.
func IsProhibitedRequestHeaderName ¶
IsProhibitedRequestHeaderName reports whether name is a prohibited request-header name. Attempts to allow such request headers almost always stem from some misunderstanding of CORS.
Precondition: name is a valid and byte-lowercase header name.
func IsProhibitedResponseHeaderName ¶
IsProhibitedResponseHeaderName reports whether name is a prohibited response-header name. Attempts to expose such response headers almost always stem from some misunderstanding of CORS.
Precondition: name is a valid and byte-lowercase header name.
func IsSafelistedResponseHeaderName ¶
IsSafelistedResponseHeaderName reports whether name is a safelisted response-header name per the Fetch standard.
Precondition: name is a valid and byte-lowercase header name.
func IsValid ¶
IsValid reports whether name is a valid header name, per the Fetch standard.
Types ¶
type SortedSet ¶ added in v0.1.3
type SortedSet struct {
// contains filtered or unexported fields
}
A SortedSet represents a mathematical set of strings sorted in lexicographical order. Each element has a unique position ranging from 0 (inclusive) to the set's cardinality (exclusive). The zero value represents an empty set.
func NewSortedSet ¶ added in v0.1.3
NewSortedSet returns a SortedSet that contains all of elems, but no other elements.
func (SortedSet) String ¶ added in v0.1.3
String sorts joins the elements of set (in lexicographical order) with a comma and returns the resulting string.
func (SortedSet) Subsumes ¶ added in v0.1.3
Subsumes reports whether csv is a sequence of comma-separated names that are
- all elements of set,
- sorted in lexicographical order,
- unique.
func (SortedSet) ToSortedSlice ¶ added in v0.2.0
ToSortedSlice applies http.CanonicalHeaderKey to each element of s and returns a sorted slice containing the results.