LEFT | RIGHT |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 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 // HTTP Response reading and parsing. | 5 // HTTP Response reading and parsing. |
6 | 6 |
7 package http | 7 package http |
8 | 8 |
9 import ( | 9 import ( |
10 "bufio" | 10 "bufio" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 key = CanonicalHeaderKey(key) | 145 key = CanonicalHeaderKey(key) |
146 | 146 |
147 oldValues, oldValuesPresent := r.Header[key] | 147 oldValues, oldValuesPresent := r.Header[key] |
148 if oldValuesPresent { | 148 if oldValuesPresent { |
149 r.Header[key] = oldValues + "," + value | 149 r.Header[key] = oldValues + "," + value |
150 } else { | 150 } else { |
151 r.Header[key] = value | 151 r.Header[key] = value |
152 } | 152 } |
153 } | 153 } |
154 | 154 |
155 // GetHeader returns the value of the response header with the given | 155 // GetHeader returns the value of the response header with the given key. |
156 // key, and true. If there were multiple headers with this key, their | 156 // If there were multiple headers with this key, their values are concatenated, |
157 // values are concatenated, with a comma delimiter. If there were no | 157 // with a comma delimiter. If there were no response headers with the given |
158 // response headers with the given key, it returns the empty string and | 158 // key, GetHeader returns an empty string. Keys are not case sensitive. |
159 // false. Keys are not case sensitive. | 159 func (r *Response) GetHeader(key string) (value string) { |
160 func (r *Response) GetHeader(key string) (string, bool) { | 160 » value, _ = r.Header[CanonicalHeaderKey(key)] |
161 » value, ok := r.Header[CanonicalHeaderKey(key)] | 161 » return |
162 » return value, ok | |
163 } | 162 } |
164 | 163 |
165 // ProtoAtLeast returns whether the HTTP protocol used | 164 // ProtoAtLeast returns whether the HTTP protocol used |
166 // in the response is at least major.minor. | 165 // in the response is at least major.minor. |
167 func (r *Response) ProtoAtLeast(major, minor int) bool { | 166 func (r *Response) ProtoAtLeast(major, minor int) bool { |
168 return r.ProtoMajor > major || | 167 return r.ProtoMajor > major || |
169 r.ProtoMajor == major && r.ProtoMinor >= minor | 168 r.ProtoMajor == major && r.ProtoMinor >= minor |
170 } | 169 } |
171 | 170 |
172 // Writes the response (header, body and trailer) in wire format. This method | 171 // Writes the response (header, body and trailer) in wire format. This method |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 } | 239 } |
241 kva = kva[0:i] | 240 kva = kva[0:i] |
242 sort.SortStrings(kva) | 241 sort.SortStrings(kva) |
243 for _, l := range kva { | 242 for _, l := range kva { |
244 if _, err := io.WriteString(w, l); err != nil { | 243 if _, err := io.WriteString(w, l); err != nil { |
245 return err | 244 return err |
246 } | 245 } |
247 } | 246 } |
248 return nil | 247 return nil |
249 } | 248 } |
LEFT | RIGHT |