makeRequestToResolvedURLOnce creates and executes a http.Request with the specified parameters, adding authentication and TLS options for the Docker client. streamLen, if not -1, specifies the length of the data expected on stream. makeRequest should generally be preferred. Note that no exponential
(ctx context.Context, method string, resolvedURL *url.URL, headers map[string][]string, stream io.Reader, streamLen int64, auth sendAuth, extraScope *authScope)
| 594 | // makeRequest should generally be preferred. |
| 595 | // Note that no exponential back off is performed when receiving an http 429 status code. |
| 596 | func (c *dockerClient) makeRequestToResolvedURLOnce(ctx context.Context, method string, resolvedURL *url.URL, headers map[string][]string, stream io.Reader, streamLen int64, auth sendAuth, extraScope *authScope) (*http.Response, error) { |
| 597 | req, err := http.NewRequestWithContext(ctx, method, resolvedURL.String(), stream) |
| 598 | if err != nil { |
| 599 | return nil, err |
| 600 | } |
| 601 | if streamLen != -1 { // Do not blindly overwrite if streamLen == -1, http.NewRequestWithContext above can figure out the length of bytes.Reader and similar objects without us having to compute it. |
| 602 | req.ContentLength = streamLen |
| 603 | } |
| 604 | req.Header.Set("Docker-Distribution-API-Version", "registry/2.0") |
| 605 | for n, h := range headers { |
| 606 | for _, hh := range h { |
| 607 | req.Header.Add(n, hh) |
| 608 | } |
| 609 | } |
| 610 | req.Header.Add("User-Agent", c.userAgent) |
| 611 | if auth == v2Auth { |
| 612 | if err := c.setupRequestAuth(req, extraScope); err != nil { |
| 613 | return nil, err |
| 614 | } |
| 615 | } |
| 616 | logrus.Debugf("%s %s", method, resolvedURL.Redacted()) |
| 617 | res, err := c.client.Do(req) |
| 618 | if err != nil { |
| 619 | return nil, err |
| 620 | } |
| 621 | if warnings := res.Header.Values("Warning"); len(warnings) != 0 { |
| 622 | c.logResponseWarnings(res, warnings) |
| 623 | } |
| 624 | return res, nil |
| 625 | } |
| 626 | |
| 627 | // logResponseWarnings logs warningHeaders from res, if any. |
| 628 | func (c *dockerClient) logResponseWarnings(res *http.Response, warningHeaders []string) { |
no test coverage detected