MCPcopy
hub / github.com/grafana/k6 / getHTTP2ServerWithCustomConnContext

Function getHTTP2ServerWithCustomConnContext

lib/netext/httpext/error_codes_test.go:345–393  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

343const connKey connKeyT = 2
344
345func 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}

Callers 2

TestHTTP2ConnectionErrorFunction · 0.85
TestHTTP2GoAwayErrorFunction · 0.85

Calls 10

GetTLSClientConfigFunction · 0.92
NewHostFunction · 0.92
NewDialerFunction · 0.92
NewResolverFunction · 0.92
NewHostsFunction · 0.92
HostnameMethod · 0.80
PortMethod · 0.80
CleanupMethod · 0.65
ParseMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…