@@ -50,7 +50,7 @@ func New(opts ...Options) (*http.Client, error) {
5050// Note: If more than one Options is provided a panic is raised.
5151func GetTransport (opts ... Options ) (http.RoundTripper , error ) {
5252 if opts == nil {
53- return http . DefaultTransport , nil
53+ return GetDefaultTransport ()
5454 }
5555
5656 clientOpts := createOptions (opts ... )
@@ -96,6 +96,16 @@ func GetTransport(opts ...Options) (http.RoundTripper, error) {
9696 return roundTripperFromMiddlewares (clientOpts , clientOpts .Middlewares , transport )
9797}
9898
99+ // GetDefaultTransport returns a clone of http.DefaultTransport, if it's of the
100+ // correct type, or an error otherwise. There are a number of places where plugin
101+ // code uses http.DefaultTransport; this supports doing so in a safer way.
102+ func GetDefaultTransport () (http.RoundTripper , error ) {
103+ if transport , ok := http .DefaultTransport .(* http.Transport ); ok {
104+ return transport .Clone (), nil
105+ }
106+ return nil , fmt .Errorf ("http.DefaultTransport is not *http.Transport but %T" , http .DefaultTransport )
107+ }
108+
99109// GetTLSConfig creates a new tls.Config given provided options.
100110// Note: If more than one Options is provided a panic is raised.
101111func GetTLSConfig (opts ... Options ) (* tls.Config , error ) {
0 commit comments