mirror of
https://github.com/AlexxIT/go2rtc.git
synced 2025-10-05 16:26:50 +08:00
Add support insecure HTTPS client
This commit is contained in:
@@ -16,6 +16,7 @@ import (
|
|||||||
func Init() {
|
func Init() {
|
||||||
streams.HandleFunc("http", handle)
|
streams.HandleFunc("http", handle)
|
||||||
streams.HandleFunc("https", handle)
|
streams.HandleFunc("https", handle)
|
||||||
|
streams.HandleFunc("httpx", handle)
|
||||||
}
|
}
|
||||||
|
|
||||||
func handle(url string) (core.Producer, error) {
|
func handle(url string) (core.Producer, error) {
|
||||||
|
@@ -12,7 +12,7 @@ import (
|
|||||||
|
|
||||||
// Do - http.Client with support Digest Authorization
|
// Do - http.Client with support Digest Authorization
|
||||||
func Do(req *http.Request) (*http.Response, error) {
|
func Do(req *http.Request) (*http.Response, error) {
|
||||||
if client == nil {
|
if secureClient == nil {
|
||||||
transport := http.DefaultTransport.(*http.Transport).Clone()
|
transport := http.DefaultTransport.(*http.Transport).Clone()
|
||||||
|
|
||||||
dial := transport.DialContext
|
dial := transport.DialContext
|
||||||
@@ -24,12 +24,32 @@ func Do(req *http.Request) (*http.Response, error) {
|
|||||||
return conn, err
|
return conn, err
|
||||||
}
|
}
|
||||||
|
|
||||||
client = &http.Client{
|
secureClient = &http.Client{
|
||||||
Timeout: time.Second * 5000,
|
Timeout: time.Second * 5000,
|
||||||
Transport: transport,
|
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
|
user := req.URL.User
|
||||||
|
|
||||||
// Hikvision won't answer on Basic auth with any headers
|
// 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
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var client *http.Client
|
var secureClient, insecureClient *http.Client
|
||||||
var connKey struct{}
|
var connKey struct{}
|
||||||
|
|
||||||
func WithConn() (context.Context, *net.Conn) {
|
func WithConn() (context.Context, *net.Conn) {
|
||||||
|
Reference in New Issue
Block a user