Skip to content

Commit 9ec5d9c

Browse files
mfrwbradfitz
authored andcommitted
net/http: document Header.Set canonicalizes the header key
Fixes #27923 Change-Id: Ia902a1966beeae56e43265fc5ed987555fa834b6 Reviewed-on: https://go-review.googlesource.com/138677 Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 3ee9672 commit 9ec5d9c

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/net/http/header.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,27 @@ type Header map[string][]string
1919

2020
// Add adds the key, value pair to the header.
2121
// It appends to any existing values associated with key.
22+
// The key is case insensitive; it is canonicalized by
23+
// textproto.CanonicalMIMEHeaderKey.
2224
func (h Header) Add(key, value string) {
2325
textproto.MIMEHeader(h).Add(key, value)
2426
}
2527

26-
// Set sets the header entries associated with key to
27-
// the single element value. It replaces any existing
28-
// values associated with key.
28+
// Set sets the header entries associated with key to the
29+
// single element value. It replaces any existing values
30+
// associated with key. The key is case insensitive; it is
31+
// canonicalized by textproto.CanonicalMIMEHeaderKey.
32+
// To use non-canonical keys, assign to the map directly.
2933
func (h Header) Set(key, value string) {
3034
textproto.MIMEHeader(h).Set(key, value)
3135
}
3236

33-
// Get gets the first value associated with the given key.
34-
// It is case insensitive; textproto.CanonicalMIMEHeaderKey is used
35-
// to canonicalize the provided key.
36-
// If there are no values associated with the key, Get returns "".
37-
// To access multiple values of a key, or to use non-canonical keys,
38-
// access the map directly.
37+
// Get gets the first value associated with the given key. If
38+
// there are no values associated with the key, Get returns "".
39+
// It is case insensitive; textproto.CanonicalMIMEHeaderKey is
40+
// used to canonicalize the provided key. To access multiple
41+
// values of a key, or to use non-canonical keys, access the
42+
// map directly.
3943
func (h Header) Get(key string) string {
4044
return textproto.MIMEHeader(h).Get(key)
4145
}
@@ -49,6 +53,8 @@ func (h Header) get(key string) string {
4953
}
5054

5155
// Del deletes the values associated with key.
56+
// The key is case insensitive; it is canonicalized by
57+
// textproto.CanonicalMIMEHeaderKey.
5258
func (h Header) Del(key string) {
5359
textproto.MIMEHeader(h).Del(key)
5460
}

0 commit comments

Comments
 (0)