From 033272f38afd076797ba7680576c94f44858cdbd Mon Sep 17 00:00:00 2001 From: starainrt Date: Mon, 22 Aug 2022 16:22:22 +0800 Subject: [PATCH] add tls config --- curl.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/curl.go b/curl.go index 6bd27b6..b11e5ac 100644 --- a/curl.go +++ b/curl.go @@ -59,6 +59,7 @@ type RequestOpts struct { CustomTransport *http.Transport Queries map[string]string DisableRedirect bool + TlsConfig *tls.Config } type RequestOpt func(opt *RequestOpts) @@ -81,6 +82,12 @@ func WithHeader(key, val string) RequestOpt { } } +func WithTlsConfig(tlscfg *tls.Config) RequestOpt { + return func(opt *RequestOpts) { + opt.TlsConfig = tlscfg + } +} + func WithHeaderMap(header map[string]string) RequestOpt { return func(opt *RequestOpts) { for key, val := range header { @@ -205,6 +212,9 @@ func NewRequests(url string, rawdata []byte, method string, opts ...RequestOpt) } req.CustomTransport.TLSClientConfig.InsecureSkipVerify = true } + if req.TlsConfig != nil { + req.CustomTransport.TLSClientConfig = req.TlsConfig + } req.CustomTransport.DialContext = func(ctx context.Context, netw, addr string) (net.Conn, error) { c, err := net.DialTimeout(netw, addr, req.DialTimeout) if err != nil {