Skip to content

Commit

Permalink
Fix custom https client
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Nov 5, 2023
1 parent 50e2a62 commit bcbebd5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/tcp/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ func Do(req *http.Request) (*http.Response, error) {
}
}

if secure != nil {
ctx := context.WithValue(req.Context(), secureKey, secure)
req = req.WithContext(ctx)
}

if client == nil {
transport := http.DefaultTransport.(*http.Transport).Clone()

Expand All @@ -43,6 +48,7 @@ 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)
if err = tlsConn.Handshake(); err != nil {
return nil, err
Expand Down Expand Up @@ -122,7 +128,7 @@ func Do(req *http.Request) (*http.Response, error) {
}

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

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

0 comments on commit bcbebd5

Please sign in to comment.