mirror of
https://github.com/golang/go
synced 2024-10-07 07:31:21 -06:00
44 lines
1.5 KiB
Go
44 lines
1.5 KiB
Go
|
// Copyright 2010 The Go Authors. All rights reserved.
|
||
|
// Use of this source code is governed by a BSD-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
|
package http
|
||
|
|
||
|
import "net/textproto"
|
||
|
|
||
|
// A Header represents the key-value pairs in an HTTP header.
|
||
|
type Header map[string][]string
|
||
|
|
||
|
// Add adds the key, value pair to the header.
|
||
|
// It appends to any existing values associated with key.
|
||
|
func (h Header) Add(key, value string) {
|
||
|
textproto.MIMEHeader(h).Add(key, value)
|
||
|
}
|
||
|
|
||
|
// Set sets the header entries associated with key to
|
||
|
// the single element value. It replaces any existing
|
||
|
// values associated with key.
|
||
|
func (h Header) Set(key, value string) {
|
||
|
textproto.MIMEHeader(h).Set(key, value)
|
||
|
}
|
||
|
|
||
|
// Get gets the first value associated with the given key.
|
||
|
// If there are no values associated with the key, Get returns "".
|
||
|
// Get is a convenience method. For more complex queries,
|
||
|
// access the map directly.
|
||
|
func (h Header) Get(key string) string {
|
||
|
return textproto.MIMEHeader(h).Get(key)
|
||
|
}
|
||
|
|
||
|
// Del deletes the values associated with key.
|
||
|
func (h Header) Del(key string) {
|
||
|
textproto.MIMEHeader(h).Del(key)
|
||
|
}
|
||
|
|
||
|
// CanonicalHeaderKey returns the canonical format of the
|
||
|
// header key s. The canonicalization converts the first
|
||
|
// letter and any letter following a hyphen to upper case;
|
||
|
// the rest are converted to lowercase. For example, the
|
||
|
// canonical key for "accept-encoding" is "Accept-Encoding".
|
||
|
func CanonicalHeaderKey(s string) string { return textproto.CanonicalMIMEHeaderKey(s) }
|