(t *testing.T)
| 343 | const connKey connKeyT = 2 |
| 344 | |
| 345 | func getHTTP2ServerWithCustomConnContext(t *testing.T) *httpmultibin.HTTPMultiBin { |
| 346 | const http2Domain = "example.com" |
| 347 | mux := http.NewServeMux() |
| 348 | http2Srv := httptest.NewUnstartedServer(mux) |
| 349 | http2Srv.EnableHTTP2 = true |
| 350 | http2Srv.Config.ConnContext = func(ctx context.Context, c net.Conn) context.Context { |
| 351 | return context.WithValue(ctx, connKey, c) |
| 352 | } |
| 353 | http2Srv.StartTLS() |
| 354 | t.Cleanup(http2Srv.Close) |
| 355 | tlsConfig := httpmultibin.GetTLSClientConfig(t, http2Srv) |
| 356 | |
| 357 | http2URL, err := url.Parse(http2Srv.URL) |
| 358 | require.NoError(t, err) |
| 359 | http2IP := net.ParseIP(http2URL.Hostname()) |
| 360 | require.NotNil(t, http2IP) |
| 361 | http2DomainValue, err := types.NewHost(http2IP, "") |
| 362 | require.NoError(t, err) |
| 363 | |
| 364 | // Set up the dialer with shorter timeouts and the custom domains |
| 365 | dialer := netext.NewDialer(net.Dialer{ |
| 366 | Timeout: 2 * time.Second, |
| 367 | KeepAlive: 10 * time.Second, |
| 368 | }, netext.NewResolver(net.LookupIP, 0, types.DNSfirst, types.DNSpreferIPv4)) |
| 369 | dialer.Hosts, err = types.NewHosts(map[string]types.Host{ |
| 370 | http2Domain: *http2DomainValue, |
| 371 | }) |
| 372 | require.NoError(t, err) |
| 373 | |
| 374 | transport := &http.Transport{ |
| 375 | DialContext: dialer.DialContext, |
| 376 | TLSClientConfig: tlsConfig, |
| 377 | } |
| 378 | require.NoError(t, http2.ConfigureTransport(transport)) |
| 379 | return &httpmultibin.HTTPMultiBin{ |
| 380 | Mux: mux, |
| 381 | ServerHTTP2: http2Srv, |
| 382 | Replacer: strings.NewReplacer( |
| 383 | "HTTP2BIN_IP_URL", http2Srv.URL, |
| 384 | "HTTP2BIN_DOMAIN", http2Domain, |
| 385 | "HTTP2BIN_URL", fmt.Sprintf("https://%s", net.JoinHostPort(http2Domain, http2URL.Port())), |
| 386 | "HTTP2BIN_IP", http2IP.String(), |
| 387 | "HTTP2BIN_PORT", http2URL.Port(), |
| 388 | ), |
| 389 | TLSClientConfig: tlsConfig, |
| 390 | Dialer: dialer, |
| 391 | HTTPTransport: transport, |
| 392 | } |
| 393 | } |
no test coverage detected
searching dependent graphs…