@@ -22,6 +22,7 @@ import (
2222 "net/http"
2323 "net/url"
2424 "os"
25+ "time"
2526
2627 "github.com/prometheus/common/log"
2728
@@ -103,22 +104,22 @@ func makeTransport(
103104 certificate string , key string ,
104105 skipServerCertCheck bool ,
105106) (* http.Transport , error ) {
106- var transport * http.Transport
107+ // Start with the DefaultTransport for sane defaults.
108+ transport := http .DefaultTransport .(* http.Transport ).Clone ()
109+ // Conservatively disable HTTP keep-alives as this program will only
110+ // ever need a single HTTP request.
111+ transport .DisableKeepAlives = true
112+ // Timeout early if the server doesn't even return the headers.
113+ transport .ResponseHeaderTimeout = time .Minute
114+ tlsConfig := & tls.Config {InsecureSkipVerify : skipServerCertCheck }
107115 if certificate != "" && key != "" {
108116 cert , err := tls .LoadX509KeyPair (certificate , key )
109117 if err != nil {
110118 return nil , err
111119 }
112- tlsConfig := & tls.Config {
113- Certificates : []tls.Certificate {cert },
114- InsecureSkipVerify : skipServerCertCheck ,
115- }
120+ tlsConfig .Certificates = []tls.Certificate {cert }
116121 tlsConfig .BuildNameToCertificate ()
117- transport = & http.Transport {TLSClientConfig : tlsConfig }
118- } else {
119- transport = & http.Transport {
120- TLSClientConfig : & tls.Config {InsecureSkipVerify : skipServerCertCheck },
121- }
122122 }
123+ transport .TLSClientConfig = tlsConfig
123124 return transport , nil
124125}
0 commit comments