parseRetryAfter determines the delay required by the "Retry-After" header in res and returns it, silently falling back to fallbackDelay if the header is missing or invalid.
(res *http.Response, fallbackDelay time.Duration)
| 504 | // parseRetryAfter determines the delay required by the "Retry-After" header in res and returns it, |
| 505 | // silently falling back to fallbackDelay if the header is missing or invalid. |
| 506 | func parseRetryAfter(res *http.Response, fallbackDelay time.Duration) time.Duration { |
| 507 | after := res.Header.Get("Retry-After") |
| 508 | if after == "" { |
| 509 | return fallbackDelay |
| 510 | } |
| 511 | logrus.Debugf("Detected 'Retry-After' header %q", after) |
| 512 | // First, check if we have a numerical value. |
| 513 | if num, err := strconv.ParseInt(after, 10, 64); err == nil { |
| 514 | return time.Duration(num) * time.Second |
| 515 | } |
| 516 | // Second, check if we have an HTTP date. |
| 517 | if t, err := http.ParseTime(after); err == nil { |
| 518 | // If the delta between the date and now is positive, use it. |
| 519 | delta := time.Until(t) |
| 520 | if delta > 0 { |
| 521 | return delta |
| 522 | } |
| 523 | logrus.Debugf("Retry-After date in the past, ignoring it") |
| 524 | return fallbackDelay |
| 525 | } |
| 526 | logrus.Debugf("Invalid Retry-After format, ignoring it") |
| 527 | return fallbackDelay |
| 528 | } |
| 529 | |
| 530 | // makeRequestToResolvedURL creates and executes a http.Request with the specified parameters, adding authentication and TLS options for the Docker client. |
| 531 | // streamLen, if not -1, specifies the length of the data expected on stream. |
no test coverage detected
searching dependent graphs…