From cbd7e1976314c5c0f8141147a81ceb0a33e26a91 Mon Sep 17 00:00:00 2001 From: kychen Date: Mon, 25 May 2020 13:31:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=81=A2=E5=A4=8Dhttp=20base=20auth.=20?= =?UTF-8?q?=E5=B9=B6=E5=9C=A8=E8=AF=B7=E6=B1=82=E8=AE=A4=E8=AF=81=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E5=90=8E=EF=BC=8C=E5=AE=9A=E4=BD=8D=E8=AF=BB=E5=8F=96?= =?UTF-8?q?=E6=8C=87=E9=92=88=E8=87=B3=E6=9C=AB=E7=AB=AF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- registry/registry.go | 14 +++++++------- registry/tokentransport.go | 4 ++++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/registry/registry.go b/registry/registry.go index 5c118efc..c63321d9 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -71,14 +71,14 @@ func WrapTransport(transport http.RoundTripper, url, username, password string) Username: username, Password: password, } - //basicAuthTransport := &BasicTransport{ - // Transport: tokenTransport, - // URL: url, - // Username: username, - // Password: password, - //} - errorTransport := &ErrorTransport{ + basicAuthTransport := &BasicTransport{ Transport: tokenTransport, + URL: url, + Username: username, + Password: password, + } + errorTransport := &ErrorTransport{ + Transport: basicAuthTransport, } return errorTransport } diff --git a/registry/tokentransport.go b/registry/tokentransport.go index 4e858b04..05760951 100644 --- a/registry/tokentransport.go +++ b/registry/tokentransport.go @@ -3,6 +3,7 @@ package registry import ( "encoding/json" "fmt" + "io/ioutil" "net/http" "net/url" ) @@ -20,6 +21,9 @@ func (t *TokenTransport) RoundTrip(req *http.Request) (*http.Response, error) { } if authService := isTokenDemand(resp); authService != nil { resp.Body.Close() + if req.Body != nil { + ioutil.ReadAll(req.Body) + } resp, err = t.authAndRetry(authService, req) } return resp, err