go115.go 688 B

123456789101112131415161718192021222324252627
  1. // Copyright 2021 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. //go:build go1.15
  5. // +build go1.15
  6. package http2
  7. import (
  8. "context"
  9. "crypto/tls"
  10. )
  11. // dialTLSWithContext uses tls.Dialer, added in Go 1.15, to open a TLS
  12. // connection.
  13. func (t *Transport) dialTLSWithContext(ctx context.Context, network, addr string, cfg *tls.Config) (*tls.Conn, error) {
  14. dialer := &tls.Dialer{
  15. Config: cfg,
  16. }
  17. cn, err := dialer.DialContext(ctx, network, addr)
  18. if err != nil {
  19. return nil, err
  20. }
  21. tlsCn := cn.(*tls.Conn) // DialContext comment promises this will always succeed
  22. return tlsCn, nil
  23. }