A utility to parse HTTP Retry-After headers, supporting both delta-seconds and HTTP-date formats. Use this to handle rate-limiting signals from LLM APIs reliably.
// Source: https://github.com/librefang/librefang | License: MIT | Copyright 2024 LibreFang Contributors // Provided via justclaw.it.com; keep this notice with the code. //! `Retry-After` HTTP header parsing. //! //! Per RFC 7231 §7.1.3 the `Retry-After` header value can be either: //! //! 1. **Delta-seconds** — a non-negative integer giving the number of //! seconds to wait, e.g. `Retry-After: 120`. //! 2. **HTTP-date** — an absolute timestamp in IMF-fixdate format, //! e.g. `Retry-After: Wed, 21 Oct 2015 07:28:00 GMT`. //! //! Real LLM providers send delta-seconds in practice, but the spec //! permits either form and a few middleware layers / CDNs do emit //! HTTP-date. Drivers that only handle the delta-seconds form silently //! fall back to a hardcoded default whenever the serve ... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key