| 411 | } |
| 412 | |
| 413 | func (h *httpProxy) Start(t *testing.T) (url string) { |
| 414 | t.Helper() |
| 415 | h.Lock() |
| 416 | defer h.Unlock() |
| 417 | ln, err := net.Listen("tcp", "127.0.0.1:0") |
| 418 | if err != nil { |
| 419 | t.Fatalf("listening for HTTP proxy: %v", err) |
| 420 | } |
| 421 | h.ln = ln |
| 422 | h.rp = httputil.ReverseProxy{ |
| 423 | Director: func(*http.Request) {}, |
| 424 | Transport: &http.Transport{ |
| 425 | DialContext: h.dialAndRecord, |
| 426 | TLSClientConfig: &tls.Config{ |
| 427 | InsecureSkipVerify: true, |
| 428 | }, |
| 429 | TLSNextProto: map[string]func(string, *tls.Conn) http.RoundTripper{}, |
| 430 | }, |
| 431 | } |
| 432 | h.clientConnAddrs = map[string]bool{} |
| 433 | h.s.Handler = h |
| 434 | if h.useTLS { |
| 435 | h.s.TLSConfig = tlsConfig(t) |
| 436 | go h.s.ServeTLS(h.ln, "", "") |
| 437 | return fmt.Sprintf("https://%s", ln.Addr().String()) |
| 438 | } else { |
| 439 | go h.s.Serve(h.ln) |
| 440 | return fmt.Sprintf("http://%s", ln.Addr().String()) |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | func (h *httpProxy) Close() { |
| 445 | h.Lock() |