MCPcopy
hub / github.com/nats-io/nats.go / startHeaderCatcher

Function startHeaderCatcher

ws_test.go:686–718  ·  view source on GitHub ↗

--- helpers ---

(t *testing.T)

Source from the content-addressed store, hash-verified

684// --- helpers ---
685
686func 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
720func hasHeaderValue(headers []string, name, want string) bool {
721 prefix := strings.ToLower(name) + ":"

Calls 4

FatalfMethod · 0.80
ReadStringMethod · 0.80
CloseMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected