Skip to content
This repository was archived by the owner on Mar 16, 2024. It is now read-only.

Commit 0806579

Browse files
committed
fix(transport): fix request body not send again when not authorized
Under normal circumstances, the body of req will be read to EOF when the first request is made. If the first request is due to the permission reason and there is no request to complete, it needs to re-request after obtaining the token. But at this time req's body has reached EOF and may even be closed, so when resending the request, you need to reset the body so that the next request can re-read the body.
1 parent afc9e1a commit 0806579

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

registry/tokentransport.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ func (t *TokenTransport) RoundTrip(req *http.Request) (*http.Response, error) {
1919
return resp, err
2020
}
2121
if authService := isTokenDemand(resp); authService != nil {
22-
resp.Body.Close()
22+
_ = resp.Body.Close()
23+
if req.GetBody != nil {
24+
req.Body, err = req.GetBody()
25+
if err != nil {
26+
return resp, err
27+
}
28+
}
2329
resp, err = t.authAndRetry(authService, req)
2430
}
2531
return resp, err

0 commit comments

Comments
 (0)