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 package http_test | 5 package http_test |
6 | 6 |
7 import ( | 7 import ( |
8 "bufio" | 8 "bufio" |
9 "bytes" | 9 "bytes" |
10 "encoding/base64" | 10 "encoding/base64" |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 {"Basic " + base64.StdEncoding.EncodeToString([]byte(":")), "", "", true
}, | 449 {"Basic " + base64.StdEncoding.EncodeToString([]byte(":")), "", "", true
}, |
450 {"Basic" + base64.StdEncoding.EncodeToString([]byte("Aladdin:open sesame
")), "", "", false}, | 450 {"Basic" + base64.StdEncoding.EncodeToString([]byte("Aladdin:open sesame
")), "", "", false}, |
451 {base64.StdEncoding.EncodeToString([]byte("Aladdin:open sesame")), "", "
", false}, | 451 {base64.StdEncoding.EncodeToString([]byte("Aladdin:open sesame")), "", "
", false}, |
452 {"Basic ", "", "", false}, | 452 {"Basic ", "", "", false}, |
453 {"Basic Aladdin:open sesame", "", "", false}, | 453 {"Basic Aladdin:open sesame", "", "", false}, |
454 {`Digest username="Aladdin"`, "", "", false}, | 454 {`Digest username="Aladdin"`, "", "", false}, |
455 } | 455 } |
456 | 456 |
457 func TestParseBasicAuth(t *testing.T) { | 457 func TestParseBasicAuth(t *testing.T) { |
458 for _, tt := range parseBasicAuthTests { | 458 for _, tt := range parseBasicAuthTests { |
459 » » username, password, ok := ParseBasicAuth(tt.header) | 459 » » r, _ := NewRequest("GET", "http://example.com/", nil) |
| 460 » » r.Header.Set("Authorization", tt.header) |
| 461 » » username, password, ok := r.BasicAuth() |
460 if ok != tt.ok || username != tt.username || password != tt.pass
word { | 462 if ok != tt.ok || username != tt.username || password != tt.pass
word { |
461 » » » t.Errorf("ParseBasicAuth(%s) = %#v, want %#v", tt.header
, parseBasicAuthTest{username, password, ok}, | 463 » » » t.Errorf("BasicAuth() = %#v, want %#v", getBasicAuthTest
{username, password, ok}, |
462 » » » » parseBasicAuthTest{tt.username, tt.password, tt.
ok}) | 464 » » » » getBasicAuthTest{tt.username, tt.password, tt.ok
}) |
463 } | 465 } |
464 } | 466 } |
465 } | 467 } |
466 | 468 |
467 type logWrites struct { | 469 type logWrites struct { |
468 t *testing.T | 470 t *testing.T |
469 dst *[]string | 471 dst *[]string |
470 } | 472 } |
471 | 473 |
472 func (l logWrites) WriteByte(c byte) error { | 474 func (l logWrites) WriteByte(c byte) error { |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 Connection: keep-alive | 671 Connection: keep-alive |
670 `) | 672 `) |
671 } | 673 } |
672 | 674 |
673 func BenchmarkReadRequestWrk(b *testing.B) { | 675 func BenchmarkReadRequestWrk(b *testing.B) { |
674 // wrk -t 1 -r 1 -c 1 http://localhost:8080/ | 676 // wrk -t 1 -r 1 -c 1 http://localhost:8080/ |
675 benchmarkReadRequest(b, `GET / HTTP/1.1 | 677 benchmarkReadRequest(b, `GET / HTTP/1.1 |
676 Host: localhost:8080 | 678 Host: localhost:8080 |
677 `) | 679 `) |
678 } | 680 } |
LEFT | RIGHT |