Add support insecure HTTPS client

This commit is contained in:
Alexey Khit
2023-04-29 17:00:52 +03:00
parent 1e14dc9ab2
commit d276311fcf
2 changed files with 24 additions and 3 deletions

View File

@@ -12,7 +12,7 @@ import (
// Do - http.Client with support Digest Authorization
func Do(req *http.Request) (*http.Response, error) {
if client == nil {
if secureClient == nil {
transport := http.DefaultTransport.(*http.Transport).Clone()
dial := transport.DialContext
@@ -24,12 +24,32 @@ func Do(req *http.Request) (*http.Response, error) {
return conn, err
}
client = &http.Client{
secureClient = &http.Client{
Timeout: time.Second * 5000,
Transport: transport,
}
}
var client *http.Client
if req.URL.Scheme == "httpx" {
req.URL.Scheme = "https"
if insecureClient == nil {
transport := secureClient.Transport.(*http.Transport).Clone()
transport.TLSClientConfig.InsecureSkipVerify = true
insecureClient = &http.Client{
Timeout: secureClient.Timeout,
Transport: transport,
}
}
client = insecureClient
} else {
client = secureClient
}
user := req.URL.User
// Hikvision won't answer on Basic auth with any headers
@@ -92,7 +112,7 @@ func Do(req *http.Request) (*http.Response, error) {
return res, nil
}
var client *http.Client
var secureClient, insecureClient *http.Client
var connKey struct{}
func WithConn() (context.Context, *net.Conn) {