mirror of
https://github.com/stablyai/orca.git
synced 2026-11-01 01:27:35 +00:00
Cursor parsed Retry-After with a bare Number(), so a huge header could block usage refreshes for years and an HTTP-date was ignored. Claude and Cursor now both call parseUsageRetryAfterMs, which applies the 24h usage cap to the shared Retry-After parser, replacing Claude's private copy of the same algorithm. The shared parser is renamed from relay-retry-after-header/parseRelayRetryAfterMs to retry-after-header/parseRetryAfterHeaderMs: relay, the updater, mobile and usage all use it.
18 lines
547 B
TypeScript
18 lines
547 B
TypeScript
// Retry-After (RFC 9110): delta-seconds or HTTP-date. Null means the server
|
|
// asked for no pacing, so the caller keeps its own backoff.
|
|
export function parseRetryAfterHeaderMs(
|
|
value: string | null | undefined,
|
|
maxMs: number,
|
|
nowMs = Date.now()
|
|
): number | null {
|
|
if (!value) {
|
|
return null
|
|
}
|
|
const seconds = Number(value)
|
|
const delayMs = Number.isFinite(seconds) ? seconds * 1_000 : Date.parse(value) - nowMs
|
|
if (!Number.isFinite(delayMs) || delayMs <= 0) {
|
|
return null
|
|
}
|
|
return Math.min(maxMs, Math.ceil(delayMs))
|
|
}
|