@@ -151,12 +151,12 @@ func parseRetryAfter(header http.Header) (time.Duration, bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The delta-seconds form is an unsigned decimal integer (RFC 9110 §10.2.3).
|
// The delta-seconds form is an unsigned decimal integer (RFC 9110 §10.2.3).
|
||||||
// Parsing it as unsigned rejects negative or otherwise malformed values so
|
// Parse as signed 64-bit to match time.Duration's underlying type and avoid
|
||||||
// they fall back to the caller's default cooldown instead of collapsing to a
|
// unsigned-to-signed narrowing conversions. Negative or malformed values are
|
||||||
// zero/negative duration that would disable the rate-limit cooldown. A value
|
// treated as unparseable so callers can apply their default cooldown. A value
|
||||||
// larger than time.Duration can hold is clamped to the maximum duration.
|
// larger than time.Duration can hold is clamped to the maximum duration.
|
||||||
if seconds, err := strconv.ParseUint(value, 10, 64); err == nil {
|
if seconds, err := strconv.ParseInt(value, 10, 64); err == nil && seconds >= 0 {
|
||||||
maxSeconds := uint64(math.MaxInt64 / int64(time.Second))
|
maxSeconds := int64(math.MaxInt64 / int64(time.Second))
|
||||||
if seconds > maxSeconds {
|
if seconds > maxSeconds {
|
||||||
return time.Duration(math.MaxInt64), true
|
return time.Duration(math.MaxInt64), true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user