@@ -50,7 +50,7 @@ func New(opts ...Options) (*http.Client, error) {
50
50
// Note: If more than one Options is provided a panic is raised.
51
51
func GetTransport (opts ... Options ) (http.RoundTripper , error ) {
52
52
if opts == nil {
53
- return http . DefaultTransport , nil
53
+ return GetDefaultTransport ()
54
54
}
55
55
56
56
clientOpts := createOptions (opts ... )
@@ -96,6 +96,16 @@ func GetTransport(opts ...Options) (http.RoundTripper, error) {
96
96
return roundTripperFromMiddlewares (clientOpts , clientOpts .Middlewares , transport )
97
97
}
98
98
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
+
99
109
// GetTLSConfig creates a new tls.Config given provided options.
100
110
// Note: If more than one Options is provided a panic is raised.
101
111
func GetTLSConfig (opts ... Options ) (* tls.Config , error ) {
0 commit comments