add tls config

master
兔子 2 years ago
parent 93b756d9fb
commit 033272f38a

@ -59,6 +59,7 @@ type RequestOpts struct {
CustomTransport *http.Transport CustomTransport *http.Transport
Queries map[string]string Queries map[string]string
DisableRedirect bool DisableRedirect bool
TlsConfig *tls.Config
} }
type RequestOpt func(opt *RequestOpts) 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 { func WithHeaderMap(header map[string]string) RequestOpt {
return func(opt *RequestOpts) { return func(opt *RequestOpts) {
for key, val := range header { for key, val := range header {
@ -205,6 +212,9 @@ func NewRequests(url string, rawdata []byte, method string, opts ...RequestOpt)
} }
req.CustomTransport.TLSClientConfig.InsecureSkipVerify = true 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) { req.CustomTransport.DialContext = func(ctx context.Context, netw, addr string) (net.Conn, error) {
c, err := net.DialTimeout(netw, addr, req.DialTimeout) c, err := net.DialTimeout(netw, addr, req.DialTimeout)
if err != nil { if err != nil {

Loading…
Cancel
Save