1
0
mirror of https://github.com/distribution/distribution synced 2024-11-12 05:45:51 +01:00

make it possible to wrap the client transport in another one

Signed-off-by: Mike Lundy <mike@fluffypenguin.org>
This commit is contained in:
Mike Lundy 2019-08-22 17:33:51 -04:00
parent 1fb7fffdb2
commit c486db2d71
No known key found for this signature in database
GPG Key ID: 9CC064ECB96D9325

@ -6,6 +6,13 @@ import (
"sync" "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 // RequestModifier represents an object which will do an inplace
// modification of an HTTP request. // modification of an HTTP request.
type RequestModifier interface { 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 // NewTransport creates a new transport which will apply modifiers to
// the request on a RoundTrip call. // the request on a RoundTrip call.
func NewTransport(base http.RoundTripper, modifiers ...RequestModifier) http.RoundTripper { func NewTransport(base http.RoundTripper, modifiers ...RequestModifier) http.RoundTripper {
return &transport{ return DefaultTransportWrapper(
Modifiers: modifiers, &transport{
Base: base, Modifiers: modifiers,
} Base: base,
})
} }
// transport is an http.RoundTripper that makes HTTP requests after // transport is an http.RoundTripper that makes HTTP requests after