Skip to content

Commit

Permalink
fix Transport.SetDialTLS not work in http2
Browse files Browse the repository at this point in the history
  • Loading branch information
imroc committed Dec 1, 2022
1 parent 51a6c64 commit d673df0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 33 deletions.
20 changes: 13 additions & 7 deletions internal/http2/go115.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,24 @@ import (
"context"
"crypto/tls"
reqtls "github.com/imroc/req/v3/pkg/tls"
"net"
)

// dialTLSWithContext uses tls.Dialer, added in Go 1.15, to open a TLS
// connection.
func (t *Transport) dialTLSWithContext(ctx context.Context, network, addr string, cfg *tls.Config) (reqtls.Conn, error) {
dialer := &tls.Dialer{
Config: cfg,
func (t *Transport) dialTLSWithContext(ctx context.Context, network, addr string, cfg *tls.Config) (tlsCn reqtls.Conn, err error) {
var conn net.Conn
if t.DialTLSContext != nil {
conn, err = t.DialTLSContext(ctx, network, addr)
} else {
dialer := &tls.Dialer{
Config: cfg,
}
conn, err = dialer.DialContext(ctx, network, addr)
}
cn, err := dialer.DialContext(ctx, network, addr)
if err != nil {
return nil, err
return
}
tlsCn := cn.(reqtls.Conn) // DialContext comment promises this will always succeed
return tlsCn, nil
tlsCn = conn.(reqtls.Conn)
return
}
26 changes: 0 additions & 26 deletions internal/http2/not_go115.go

This file was deleted.

0 comments on commit d673df0

Please sign in to comment.