(ctx context.Context, requestURL string, accept string, kind string, maxSize int64)
| 136 | } |
| 137 | |
| 138 | func (c Client) get(ctx context.Context, requestURL string, accept string, kind string, maxSize int64) ([]byte, error) { |
| 139 | currentURL := strings.TrimSpace(requestURL) |
| 140 | for redirects := 0; ; redirects++ { |
| 141 | if errURL := validatePluginStoreRequestURL(c.Auth, currentURL, kind); errURL != nil { |
| 142 | return nil, errURL |
| 143 | } |
| 144 | headers := http.Header{ |
| 145 | "Accept": []string{accept}, |
| 146 | "User-Agent": []string{c.userAgent()}, |
| 147 | } |
| 148 | if errAuth := applyPluginStoreAuth(headers, c.Auth, currentURL, kind); errAuth != nil { |
| 149 | return nil, errAuth |
| 150 | } |
| 151 | resp, errDo := pluginStoreGetNoRedirect(ctx, c.httpClient(), currentURL, headers) |
| 152 | if errDo != nil { |
| 153 | return nil, errDo |
| 154 | } |
| 155 | if pluginStoreRedirectStatus(resp.StatusCode) { |
| 156 | nextURL, errRedirect := pluginStoreRedirectURL(resp, currentURL) |
| 157 | if errClose := resp.Body.Close(); errClose != nil { |
| 158 | log.WithError(errClose).Debug("failed to close plugin store redirect body") |
| 159 | } |
| 160 | if errRedirect != nil { |
| 161 | return nil, errRedirect |
| 162 | } |
| 163 | if redirects >= maxPluginStoreRedirects { |
| 164 | return nil, fmt.Errorf("stopped after %d redirects", maxPluginStoreRedirects) |
| 165 | } |
| 166 | currentURL = nextURL |
| 167 | continue |
| 168 | } |
| 169 | return readPluginStoreResponse(resp, maxSize) |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | func (c Client) httpClient() HTTPDoer { |
| 174 | if c.HTTPClient != nil { |
no test coverage detected