Commit 9ec5d9c1 authored by Muhammad Falak R Wani's avatar Muhammad Falak R Wani Committed by Brad Fitzpatrick

net/http: document Header.Set canonicalizes the header key

Fixes #27923

Change-Id: Ia902a1966beeae56e43265fc5ed987555fa834b6
Reviewed-on: https://go-review.googlesource.com/138677Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 3ee96729
...@@ -19,23 +19,27 @@ type Header map[string][]string ...@@ -19,23 +19,27 @@ type Header map[string][]string
// Add adds the key, value pair to the header. // Add adds the key, value pair to the header.
// It appends to any existing values associated with key. // It appends to any existing values associated with key.
// The key is case insensitive; it is canonicalized by
// textproto.CanonicalMIMEHeaderKey.
func (h Header) Add(key, value string) { func (h Header) Add(key, value string) {
textproto.MIMEHeader(h).Add(key, value) textproto.MIMEHeader(h).Add(key, value)
} }
// Set sets the header entries associated with key to // Set sets the header entries associated with key to the
// the single element value. It replaces any existing // single element value. It replaces any existing values
// values associated with key. // associated with key. The key is case insensitive; it is
// canonicalized by textproto.CanonicalMIMEHeaderKey.
// To use non-canonical keys, assign to the map directly.
func (h Header) Set(key, value string) { func (h Header) Set(key, value string) {
textproto.MIMEHeader(h).Set(key, value) textproto.MIMEHeader(h).Set(key, value)
} }
// Get gets the first value associated with the given key. // Get gets the first value associated with the given key. If
// It is case insensitive; textproto.CanonicalMIMEHeaderKey is used // there are no values associated with the key, Get returns "".
// to canonicalize the provided key. // It is case insensitive; textproto.CanonicalMIMEHeaderKey is
// If there are no values associated with the key, Get returns "". // used to canonicalize the provided key. To access multiple
// To access multiple values of a key, or to use non-canonical keys, // values of a key, or to use non-canonical keys, access the
// access the map directly. // map directly.
func (h Header) Get(key string) string { func (h Header) Get(key string) string {
return textproto.MIMEHeader(h).Get(key) return textproto.MIMEHeader(h).Get(key)
} }
...@@ -49,6 +53,8 @@ func (h Header) get(key string) string { ...@@ -49,6 +53,8 @@ func (h Header) get(key string) string {
} }
// Del deletes the values associated with key. // Del deletes the values associated with key.
// The key is case insensitive; it is canonicalized by
// textproto.CanonicalMIMEHeaderKey.
func (h Header) Del(key string) { func (h Header) Del(key string) {
textproto.MIMEHeader(h).Del(key) textproto.MIMEHeader(h).Del(key)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment