From c486db2d715fd509b4d2a102337283350c7f1394 Mon Sep 17 00:00:00 2001 From: Mike Lundy Date: Thu, 22 Aug 2019 17:33:51 -0400 Subject: [PATCH] make it possible to wrap the client transport in another one Signed-off-by: Mike Lundy --- registry/client/transport/transport.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/registry/client/transport/transport.go b/registry/client/transport/transport.go index 30e45fab0..ee23829f3 100644 --- a/registry/client/transport/transport.go +++ b/registry/client/transport/transport.go @@ -6,6 +6,13 @@ import ( "sync" ) +func identityTransportWrapper(rt http.RoundTripper) http.RoundTripper { + return rt +} + +// DefaultTransportWrapper allows a user to wrap every generated transport +var DefaultTransportWrapper = identityTransportWrapper + // RequestModifier represents an object which will do an inplace // modification of an HTTP request. type RequestModifier interface { @@ -31,10 +38,11 @@ func (h headerModifier) ModifyRequest(req *http.Request) error { // NewTransport creates a new transport which will apply modifiers to // the request on a RoundTrip call. func NewTransport(base http.RoundTripper, modifiers ...RequestModifier) http.RoundTripper { - return &transport{ - Modifiers: modifiers, - Base: base, - } + return DefaultTransportWrapper( + &transport{ + Modifiers: modifiers, + Base: base, + }) } // transport is an http.RoundTripper that makes HTTP requests after