add tls config

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

@ -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 {

Loading…
Cancel
Save