diff --git a/app/vmalert/main.go b/app/vmalert/main.go index 4d982a3ece..ce49ab8812 100644 --- a/app/vmalert/main.go +++ b/app/vmalert/main.go @@ -24,7 +24,6 @@ import ( "github.com/VictoriaMetrics/VictoriaMetrics/lib/httpserver" "github.com/VictoriaMetrics/VictoriaMetrics/lib/logger" "github.com/VictoriaMetrics/VictoriaMetrics/lib/procutil" - "github.com/VictoriaMetrics/fasthttp" "github.com/VictoriaMetrics/metrics" ) @@ -283,21 +282,15 @@ func getTLSConfig(certFile, keyFile, CAFile, serverName *string, insecureSkipVer } func getTransport(URL, certFile, keyFile, CAFile, serverName *string, insecureSkipVerify *bool) (*http.Transport, error) { - var u fasthttp.URI - u.Update(*URL) - - var t *http.Transport - if string(u.Scheme()) == "https" { - t = http.DefaultTransport.(*http.Transport).Clone() - - tlsCfg, err := getTLSConfig(certFile, keyFile, CAFile, serverName, insecureSkipVerify) - if err != nil { - return nil, err - } - - t.TLSClientConfig = tlsCfg + t := http.DefaultTransport.(*http.Transport).Clone() + if !strings.HasPrefix(*URL, "https") { + return t, nil } - + tlsCfg, err := getTLSConfig(certFile, keyFile, CAFile, serverName, insecureSkipVerify) + if err != nil { + return nil, err + } + t.TLSClientConfig = tlsCfg return t, nil } diff --git a/app/vmalert/main_test.go b/app/vmalert/main_test.go index 0bd574cba2..20fa377c8d 100644 --- a/app/vmalert/main_test.go +++ b/app/vmalert/main_test.go @@ -87,15 +87,12 @@ func TestGetTransport(t *testing.T) { var certFile, keyFile, CAFile, serverName string var insecureSkipVerify bool URL := "http://victoriametrics.com" - tr, err := getTransport(&URL, &certFile, &keyFile, &CAFile, &serverName, &insecureSkipVerify) + _, err := getTransport(&URL, &certFile, &keyFile, &CAFile, &serverName, &insecureSkipVerify) if err != nil { t.Errorf("unexpected error %s", err) } - if tr != nil { - t.Errorf("expected Transport to be nil, got %v", tr) - } URL = "https://victoriametrics.com" - tr, err = getTransport(&URL, &certFile, &keyFile, &CAFile, &serverName, &insecureSkipVerify) + tr, err := getTransport(&URL, &certFile, &keyFile, &CAFile, &serverName, &insecureSkipVerify) if err != nil { t.Errorf("unexpected error %s", err) }