--- helpers ---
(t *testing.T)
| 684 | // --- helpers --- |
| 685 | |
| 686 | func startHeaderCatcher(t *testing.T) (addr string, got chan []string, closer func()) { |
| 687 | t.Helper() |
| 688 | ln, err := net.Listen("tcp", "127.0.0.1:0") |
| 689 | if err != nil { |
| 690 | t.Fatalf("listen: %v", err) |
| 691 | } |
| 692 | got = make(chan []string, 1) |
| 693 | |
| 694 | go func() { |
| 695 | conn, err := ln.Accept() |
| 696 | if err != nil { |
| 697 | // surface nothing; test will timeout |
| 698 | return |
| 699 | } |
| 700 | defer conn.Close() |
| 701 | r := bufio.NewReader(conn) |
| 702 | var lines []string |
| 703 | for { |
| 704 | s, err := r.ReadString('\n') |
| 705 | if err != nil { |
| 706 | break |
| 707 | } |
| 708 | s = strings.TrimRight(s, "\r\n") |
| 709 | if s == "" { // end of HTTP headers |
| 710 | break |
| 711 | } |
| 712 | lines = append(lines, s) |
| 713 | } |
| 714 | got <- lines |
| 715 | }() |
| 716 | |
| 717 | return ln.Addr().String(), got, func() { _ = ln.Close() } |
| 718 | } |
| 719 | |
| 720 | func hasHeaderValue(headers []string, name, want string) bool { |
| 721 | prefix := strings.ToLower(name) + ":" |
no test coverage detected