parseSecondaryRate parses the secondary rate related headers, and returns the time to retry after.
(r *http.Response)
| 1090 | // parseSecondaryRate parses the secondary rate related headers, |
| 1091 | // and returns the time to retry after. |
| 1092 | func parseSecondaryRate(r *http.Response) *time.Duration { |
| 1093 | // According to GitHub support, the "Retry-After" header value will be |
| 1094 | // an integer which represents the number of seconds that one should |
| 1095 | // wait before resuming making requests. |
| 1096 | if v := r.Header.Get(headerRetryAfter); v != "" { |
| 1097 | retryAfterSeconds, _ := strconv.ParseInt(v, 10, 64) // Error handling is noop. |
| 1098 | retryAfter := time.Duration(retryAfterSeconds) * time.Second |
| 1099 | return &retryAfter |
| 1100 | } |
| 1101 | |
| 1102 | // According to GitHub support, endpoints might return x-ratelimit-reset instead, |
| 1103 | // as an integer which represents the number of seconds since epoch UTC, |
| 1104 | // representing the time to resume making requests. |
| 1105 | if v := r.Header.Get(HeaderRateReset); v != "" { |
| 1106 | secondsSinceEpoch, _ := strconv.ParseInt(v, 10, 64) // Error handling is noop. |
| 1107 | retryAfter := time.Until(time.Unix(secondsSinceEpoch, 0)) |
| 1108 | return &retryAfter |
| 1109 | } |
| 1110 | |
| 1111 | return nil |
| 1112 | } |
| 1113 | |
| 1114 | // parseTokenExpiration parses the TokenExpiration related headers. |
| 1115 | // Returns 0001-01-01 if the header is not defined or could not be parsed. |
no test coverage detected
searching dependent graphs…