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

Commit

Permalink
fix(transport): fix request body not send again when not authorized
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Luckyboys committed Oct 9, 2019
1 parent afc9e1a commit 1ebd5fc
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion registry/tokentransport.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,21 @@ type TokenTransport struct {
}

func (t *TokenTransport) RoundTrip(req *http.Request) (*http.Response, error) {

var err error

resp, err := t.Transport.RoundTrip(req)
if err != nil {
return resp, err
}
if authService := isTokenDemand(resp); authService != nil {
resp.Body.Close()
_ = resp.Body.Close()
if req.GetBody != nil {
req.Body, err = req.GetBody()
if err != nil {
return resp, err
}
}
resp, err = t.authAndRetry(authService, req)
}
return resp, err
Expand Down

0 comments on commit 1ebd5fc

Please sign in to comment.