From bcbebd5a362d8f9e8d2be5f3201d9ee8fa6dfa1b Mon Sep 17 00:00:00 2001 From: Alex X Date: Sun, 5 Nov 2023 08:39:07 +0300 Subject: [PATCH] Fix custom https client --- pkg/tcp/request.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/tcp/request.go b/pkg/tcp/request.go index f46e7a92..6955a0d3 100644 --- a/pkg/tcp/request.go +++ b/pkg/tcp/request.go @@ -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() @@ -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 @@ -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)