Skip to content

Commit

Permalink
Fix https source, again
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Nov 15, 2023
1 parent befa6bd commit c9ae6dc
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions pkg/tcp/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ func Do(req *http.Request) (*http.Response, error) {
case "https":
if hostname := req.URL.Hostname(); IsIP(hostname) {
secure = &tls.Config{InsecureSkipVerify: true}
} else {
secure = &tls.Config{ServerName: hostname}
}
}

Expand All @@ -48,11 +46,21 @@ func Do(req *http.Request) (*http.Response, error) {
if err != nil {
return nil, err
}
secure := ctx.Value(connKey).(*tls.Config)
tlsConn := tls.Client(conn, secure)

var conf *tls.Config
if v, ok := ctx.Value(secureKey).(*tls.Config); ok {
conf = v
} else if host, _, err := net.SplitHostPort(addr); err != nil {
conf = &tls.Config{ServerName: addr}
} else {
conf = &tls.Config{ServerName: host}
}

tlsConn := tls.Client(conn, conf)
if err = tlsConn.Handshake(); err != nil {
return nil, err
}

if pconn, ok := ctx.Value(connKey).(*net.Conn); ok {
*pconn = tlsConn
}
Expand Down Expand Up @@ -128,7 +136,11 @@ func Do(req *http.Request) (*http.Response, error) {
}

var client *http.Client
var connKey, secureKey struct{}

type key string

var connKey = key("conn")
var secureKey = key("secure")

func WithConn() (context.Context, *net.Conn) {
pconn := new(net.Conn)
Expand Down

0 comments on commit c9ae6dc

Please sign in to comment.