OLD | NEW |
1 // Copyright 2010 The Go Authors. All rights reserved. | 1 // Copyright 2010 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package http | 5 package http |
6 | 6 |
7 import ( | 7 import ( |
8 "fmt" | 8 "fmt" |
9 "io" | 9 "io" |
10 "net/textproto" | 10 "net/textproto" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 | 49 |
50 // WriteSubset writes a header in wire format. | 50 // WriteSubset writes a header in wire format. |
51 // If exclude is not nil, keys where exclude[key] == true are not written. | 51 // If exclude is not nil, keys where exclude[key] == true are not written. |
52 func (h Header) WriteSubset(w io.Writer, exclude map[string]bool) os.Error { | 52 func (h Header) WriteSubset(w io.Writer, exclude map[string]bool) os.Error { |
53 keys := make([]string, 0, len(h)) | 53 keys := make([]string, 0, len(h)) |
54 for k := range h { | 54 for k := range h { |
55 if exclude == nil || !exclude[k] { | 55 if exclude == nil || !exclude[k] { |
56 keys = append(keys, k) | 56 keys = append(keys, k) |
57 } | 57 } |
58 } | 58 } |
59 » sort.SortStrings(keys) | 59 » sort.Strings(keys) |
60 for _, k := range keys { | 60 for _, k := range keys { |
61 for _, v := range h[k] { | 61 for _, v := range h[k] { |
62 v = strings.Replace(v, "\n", " ", -1) | 62 v = strings.Replace(v, "\n", " ", -1) |
63 v = strings.Replace(v, "\r", " ", -1) | 63 v = strings.Replace(v, "\r", " ", -1) |
64 v = strings.TrimSpace(v) | 64 v = strings.TrimSpace(v) |
65 if _, err := fmt.Fprintf(w, "%s: %s\r\n", k, v); err !=
nil { | 65 if _, err := fmt.Fprintf(w, "%s: %s\r\n", k, v); err !=
nil { |
66 return err | 66 return err |
67 } | 67 } |
68 } | 68 } |
69 } | 69 } |
70 return nil | 70 return nil |
71 } | 71 } |
72 | 72 |
73 // CanonicalHeaderKey returns the canonical format of the | 73 // CanonicalHeaderKey returns the canonical format of the |
74 // header key s. The canonicalization converts the first | 74 // header key s. The canonicalization converts the first |
75 // letter and any letter following a hyphen to upper case; | 75 // letter and any letter following a hyphen to upper case; |
76 // the rest are converted to lowercase. For example, the | 76 // the rest are converted to lowercase. For example, the |
77 // canonical key for "accept-encoding" is "Accept-Encoding". | 77 // canonical key for "accept-encoding" is "Accept-Encoding". |
78 func CanonicalHeaderKey(s string) string { return textproto.CanonicalMIMEHeaderK
ey(s) } | 78 func CanonicalHeaderKey(s string) string { return textproto.CanonicalMIMEHeaderK
ey(s) } |
OLD | NEW |