createTestHTTPClient creates an *http.Client that will be used to send requests to the specified dnsProxy.
(dnsProxy *Proxy, caPem []byte, http3Enabled bool)
| 415 | // createTestHTTPClient creates an *http.Client that will be used to send |
| 416 | // requests to the specified dnsProxy. |
| 417 | func createTestHTTPClient(dnsProxy *Proxy, caPem []byte, http3Enabled bool) (client *http.Client) { |
| 418 | // prepare roots list so that the server cert was successfully validated. |
| 419 | roots := x509.NewCertPool() |
| 420 | roots.AppendCertsFromPEM(caPem) |
| 421 | tlsClientConfig := &tls.Config{ |
| 422 | ServerName: tlsServerName, |
| 423 | RootCAs: roots, |
| 424 | } |
| 425 | |
| 426 | var transport http.RoundTripper |
| 427 | |
| 428 | if http3Enabled { |
| 429 | tlsClientConfig.NextProtos = []string{"h3"} |
| 430 | |
| 431 | transport = &http3.Transport{ |
| 432 | Dial: func( |
| 433 | ctx context.Context, |
| 434 | _ string, |
| 435 | tlsCfg *tls.Config, |
| 436 | cfg *quic.Config, |
| 437 | ) (*quic.Conn, error) { |
| 438 | addr := dnsProxy.Addr(ProtoHTTPS).String() |
| 439 | return quic.DialAddrEarly(ctx, addr, tlsCfg, cfg) |
| 440 | }, |
| 441 | TLSClientConfig: tlsClientConfig, |
| 442 | QUICConfig: &quic.Config{}, |
| 443 | DisableCompression: true, |
| 444 | } |
| 445 | } else { |
| 446 | dialer := &net.Dialer{ |
| 447 | Timeout: defaultTimeout, |
| 448 | } |
| 449 | dialContext := func(ctx context.Context, network, addr string) (net.Conn, error) { |
| 450 | // Route request to the DNS-over-HTTPS server address. |
| 451 | return dialer.DialContext(ctx, network, dnsProxy.Addr(ProtoHTTPS).String()) |
| 452 | } |
| 453 | |
| 454 | tlsClientConfig.NextProtos = []string{"h2", "http/1.1"} |
| 455 | transport = &http.Transport{ |
| 456 | TLSClientConfig: tlsClientConfig, |
| 457 | DisableCompression: true, |
| 458 | DialContext: dialContext, |
| 459 | ForceAttemptHTTP2: true, |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | return &http.Client{ |
| 464 | Transport: transport, |
| 465 | Timeout: defaultTimeout, |
| 466 | } |
| 467 | } |
no test coverage detected
searching dependent graphs…