parseRetryAfterHeader parses a Retry-After header value. Supports both seconds (integer) and HTTP-date formats per RFC 7231 §7.1.3. Returns 0 if the value is empty, invalid, or results in a non-positive duration.
(value string)
| 547 | // Supports both seconds (integer) and HTTP-date formats per RFC 7231 §7.1.3. |
| 548 | // Returns 0 if the value is empty, invalid, or results in a non-positive duration. |
| 549 | func parseRetryAfterHeader(value string) time.Duration { |
| 550 | if value == "" { |
| 551 | return 0 |
| 552 | } |
| 553 | // Try integer seconds first (most common for rate limits) |
| 554 | if seconds, err := strconv.Atoi(value); err == nil && seconds > 0 { |
| 555 | return time.Duration(seconds) * time.Second |
| 556 | } |
| 557 | // Try HTTP-date format |
| 558 | if t, err := http.ParseTime(value); err == nil { |
| 559 | d := time.Until(t) |
| 560 | if d > 0 { |
| 561 | return d |
| 562 | } |
| 563 | } |
| 564 | return 0 |
| 565 | } |
| 566 | |
| 567 | // ClassifyModelError classifies an error for the retry/fallback decision. |
| 568 | // |