DoWithAuth sends an HTTP request to get an HTTP response. It attempts to add authentication from netrc or git's credential helpers if necessary, supporting basic authentication.
(remote string, access creds.Access, req *http.Request)
| 24 | // authentication from netrc or git's credential helpers if necessary, |
| 25 | // supporting basic authentication. |
| 26 | func (c *Client) DoWithAuth(remote string, access creds.Access, req *http.Request) (*http.Response, error) { |
| 27 | count := 0 |
| 28 | res, err := c.doWithAuth(remote, &count, access, req, nil) |
| 29 | |
| 30 | if errors.IsAuthError(err) { |
| 31 | if len(req.Header.Get("Authorization")) == 0 { |
| 32 | // This case represents a rejected request that |
| 33 | // should have been authenticated but wasn't. Do |
| 34 | // not count this against our redirection |
| 35 | // maximum. |
| 36 | newAccess := c.Endpoints.AccessFor(access.URL()) |
| 37 | tracerx.Printf("api: http response indicates %q authentication. Resubmitting...", newAccess.Mode()) |
| 38 | return c.DoWithAuth(remote, newAccess, req) |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | return res, err |
| 43 | } |
| 44 | |
| 45 | // DoWithAuthNoRetry sends an HTTP request to get an HTTP response. It works in |
| 46 | // the same way as DoWithAuth, but will not retry the request if it fails with |