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 textproto | 5 package textproto |
6 | 6 |
7 import ( | 7 import ( |
8 "bufio" | 8 "bufio" |
9 "bytes" | 9 "bytes" |
10 "io" | 10 "io" |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 } | 234 } |
235 if code != tt.wantCode { | 235 if code != tt.wantCode { |
236 t.Errorf("#%d: code=%d, want %d", i, code, tt.wantCode) | 236 t.Errorf("#%d: code=%d, want %d", i, code, tt.wantCode) |
237 } | 237 } |
238 if msg != tt.wantMsg { | 238 if msg != tt.wantMsg { |
239 t.Errorf("#%d: msg=%q, want %q", i, msg, tt.wantMsg) | 239 t.Errorf("#%d: msg=%q, want %q", i, msg, tt.wantMsg) |
240 } | 240 } |
241 } | 241 } |
242 } | 242 } |
243 | 243 |
| 244 var clientHeaders = strings.Replace(`Host: golang.org |
| 245 Connection: keep-alive |
| 246 Cache-Control: max-age=0 |
| 247 Accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,i
mage/png,*/*;q=0.5 |
| 248 User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.3 (KHTML,
like Gecko) Chrome/6.0.472.63 Safari/534.3 |
| 249 Accept-Encoding: gzip,deflate,sdch |
| 250 Accept-Language: en-US,en;q=0.8,fr-CH;q=0.6 |
| 251 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3 |
| 252 Cookie: __utma=000000000.0000000000.0000000000.0000000000.0000000000.00; __utmb=
000000000.0.00.0000000000; __utmc=000000000; __utmz=000000000.0000000000.00.0.ut
mcsr=code.google.com|utmccn=(referral)|utmcmd=referral|utmcct=/p/go/issues/detai
l |
| 253 Non-Interned: test |
| 254 |
| 255 `, "\n", "\r\n", -1) |
| 256 |
| 257 var serverHeaders = strings.Replace(`Content-Type: text/html; charset=utf-8 |
| 258 Content-Encoding: gzip |
| 259 Date: Thu, 27 Sep 2012 09:03:33 GMT |
| 260 Server: Google Frontend |
| 261 Cache-Control: private |
| 262 Content-Length: 2298 |
| 263 Via: 1.1 proxy.example.com:80 (XXX/n.n.n-nnn) |
| 264 Connection: Close |
| 265 Non-Interned: test |
| 266 |
| 267 `, "\n", "\r\n", -1) |
| 268 |
244 func BenchmarkReadMIMEHeader(b *testing.B) { | 269 func BenchmarkReadMIMEHeader(b *testing.B) { |
245 var buf bytes.Buffer | 270 var buf bytes.Buffer |
246 br := bufio.NewReader(&buf) | 271 br := bufio.NewReader(&buf) |
247 r := NewReader(br) | 272 r := NewReader(br) |
248 for i := 0; i < b.N; i++ { | 273 for i := 0; i < b.N; i++ { |
249 » » buf.WriteString("User-Agent: not mozilla\r\nContent-Length: 2345
2\r\nContent-Type: text/html; charset-utf8\r\nFoo-Bar: foobar\r\nfoo-bar: some m
ore string\r\n\r\n") | 274 » » var want int |
| 275 » » if (i & 1) == 1 { |
| 276 » » » buf.WriteString(clientHeaders) |
| 277 » » » want = 10 |
| 278 » » } else { |
| 279 » » » buf.WriteString(serverHeaders) |
| 280 » » » want = 9 |
| 281 » » } |
250 h, err := r.ReadMIMEHeader() | 282 h, err := r.ReadMIMEHeader() |
251 if err != nil { | 283 if err != nil { |
252 b.Fatal(err) | 284 b.Fatal(err) |
253 } | 285 } |
254 » » if len(h) != 4 { | 286 » » if len(h) != want { |
255 » » » b.Fatalf("want 4") | 287 » » » b.Fatalf("wrong number of headers: got %d, want %d", len
(h), want) |
256 } | 288 } |
257 } | 289 } |
258 } | 290 } |
OLD | NEW |