From 92d58f6287c0c07a9db0509900dd1c81d89dec5d Mon Sep 17 00:00:00 2001 From: Wenkai Yin Date: Fri, 15 Apr 2016 17:06:19 +0800 Subject: [PATCH] provide NewClient() func --- utils/registry/httpclient.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/utils/registry/httpclient.go b/utils/registry/httpclient.go index 8ce993bce..78da12d91 100644 --- a/utils/registry/httpclient.go +++ b/utils/registry/httpclient.go @@ -22,6 +22,15 @@ import ( "github.com/vmware/harbor/utils/registry/auth" ) +// NewClient returns a http.Client according to the handlers provided +func NewClient(handlers []auth.Handler) *http.Client { + transport := NewAuthTransport(http.DefaultTransport, handlers) + + return &http.Client{ + Transport: transport, + } +} + // NewClientStandardAuthHandlerEmbeded return a http.Client which will authorize the request // according to the credential provided and send it again when encounters a 401 error func NewClientStandardAuthHandlerEmbeded(credential *auth.Credential) *http.Client { @@ -31,11 +40,7 @@ func NewClientStandardAuthHandlerEmbeded(credential *auth.Credential) *http.Clie handlers = append(handlers, tokenHandler) - transport := NewAuthTransport(http.DefaultTransport, handlers) - - return &http.Client{ - Transport: transport, - } + return NewClient(handlers) } // NewClientUsernameAuthHandlerEmbeded return a http.Client which will authorize the request @@ -47,11 +52,7 @@ func NewClientUsernameAuthHandlerEmbeded(username string) *http.Client { handlers = append(handlers, tokenHandler) - transport := NewAuthTransport(http.DefaultTransport, handlers) - - return &http.Client{ - Transport: transport, - } + return NewClient(handlers) } type authTransport struct {