Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: set InsecureSkipVerify only once #822

Merged
merged 1 commit into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func main() {
os.Setenv(util.ConfigFilePathENV, absPath)
}
if *skipVerify {
os.Setenv(util.SkipVerifyENV, "true")
util.SetInsecureSkipVerify()
}
if *customDNSServer != "" {
util.NewDialerResolver(*customDNSServer + ":53")
Expand Down
18 changes: 9 additions & 9 deletions util/http_client_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@ import (
"crypto/tls"
"net"
"net/http"
"os"
"time"
)

const SkipVerifyENV = "DDNS_SKIP_VERIFY"

var dialer = &net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
Expand All @@ -31,8 +28,6 @@ var defaultTransport = &http.Transport{

// CreateHTTPClient Create Default HTTP Client
func CreateHTTPClient() *http.Client {
// SkipVerfiry
defaultTransport.TLSClientConfig = &tls.Config{InsecureSkipVerify: os.Getenv(SkipVerifyENV) == "true"}
return &http.Client{
Timeout: 30 * time.Second,
Transport: defaultTransport,
Expand Down Expand Up @@ -74,18 +69,23 @@ var noProxyTcp6Transport = &http.Transport{
// CreateNoProxyHTTPClient Create NoProxy HTTP Client
func CreateNoProxyHTTPClient(network string) *http.Client {
if network == "tcp6" {
// SkipVerfiry
noProxyTcp6Transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: os.Getenv(SkipVerifyENV) == "true"}
return &http.Client{
Timeout: 30 * time.Second,
Transport: noProxyTcp6Transport,
}
}

// SkipVerfiry
noProxyTcp4Transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: os.Getenv(SkipVerifyENV) == "true"}
return &http.Client{
Timeout: 30 * time.Second,
Transport: noProxyTcp4Transport,
}
}

// SetInsecureSkipVerify 将所有 http.Transport 的 InsecureSkipVerify 设置为 true
func SetInsecureSkipVerify() {
transports := []*http.Transport{defaultTransport, noProxyTcp4Transport, noProxyTcp6Transport}

for _, transport := range transports {
transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
}
}