Daily bump.
[official-gcc.git] / libgo / go / net / textproto / header.go
bloba58df7aebca2d62ba2c05306cc7d0669a5876892
1 // Copyright 2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 package textproto
7 // A MIMEHeader represents a MIME-style header mapping
8 // keys to sets of values.
9 type MIMEHeader map[string][]string
11 // Add adds the key, value pair to the header.
12 // It appends to any existing values associated with key.
13 func (h MIMEHeader) Add(key, value string) {
14 key = CanonicalMIMEHeaderKey(key)
15 h[key] = append(h[key], value)
18 // Set sets the header entries associated with key to
19 // the single element value. It replaces any existing
20 // values associated with key.
21 func (h MIMEHeader) Set(key, value string) {
22 h[CanonicalMIMEHeaderKey(key)] = []string{value}
25 // Get gets the first value associated with the given key.
26 // It is case insensitive; CanonicalMIMEHeaderKey is used
27 // to canonicalize the provided key.
28 // If there are no values associated with the key, Get returns "".
29 // To use non-canonical keys, access the map directly.
30 func (h MIMEHeader) Get(key string) string {
31 if h == nil {
32 return ""
34 v := h[CanonicalMIMEHeaderKey(key)]
35 if len(v) == 0 {
36 return ""
38 return v[0]
41 // Values returns all values associated with the given key.
42 // It is case insensitive; CanonicalMIMEHeaderKey is
43 // used to canonicalize the provided key. To use non-canonical
44 // keys, access the map directly.
45 // The returned slice is not a copy.
46 func (h MIMEHeader) Values(key string) []string {
47 if h == nil {
48 return nil
50 return h[CanonicalMIMEHeaderKey(key)]
53 // Del deletes the values associated with key.
54 func (h MIMEHeader) Del(key string) {
55 delete(h, CanonicalMIMEHeaderKey(key))