diff --git a/cmd/http/http.go b/cmd/http/http.go index a261b0c6..167f0f13 100644 --- a/cmd/http/http.go +++ b/cmd/http/http.go @@ -16,6 +16,7 @@ import ( func Init() { streams.HandleFunc("http", handle) streams.HandleFunc("https", handle) + streams.HandleFunc("httpx", handle) } func handle(url string) (core.Producer, error) { diff --git a/pkg/tcp/request.go b/pkg/tcp/request.go index f0b76edb..5bcbc48b 100644 --- a/pkg/tcp/request.go +++ b/pkg/tcp/request.go @@ -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) {