[already possible] Respect Retry-After HTTP header
See original GitHub issueThe Retry-After response header is used to indicate how long a client should wait before sending the next request. It would be great if RetryPolicy took this into account.
Pseudocode:
var serverWaitDuration = getServerWaitDuration(response.Headers.Get("Retry-After"));
var waitDuration = Math.Max(clientWaitDuration.TotalMilliseconds, serverWaitDuration.TotalMilliseconds);
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (6 by maintainers)
Top Results From Across the Web
Retry-After HTTP header in practice - Tomasz Nurkiewicz
The Retry-After response-header field can be used with a 503 (Service Unavailable) response to indicate how long the service is expected to ...
Read more >Retry-After - HTTP - MDN Web Docs
The Retry-After response HTTP header indicates how long the user agent should wait before making a follow-up request.
Read more >Retry-after HTTP response header - does it affect anything?
The Retry-After response-header field can be used with a 503 (Service Unavailable) response to indicate how long the service is expected to ...
Read more >Retry-After HTTP Header in Practice
The Retry-After response-header field can be used with a 503 (Service Unavailable) response to indicate how long the service is expected to ...
Read more >HTTP/1.1: Header Field Definitions
The Accept request-header field can be used to specify certain media types ... The special "*" symbol in an Accept-Encoding field matches any...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @nmurf! You can already do this with current Polly. You can use a wait-and-retry overload taking the returned response as input to the
sleepDurationProvider
delegate. Something like:This is pseudo-code (for speed of response) : you may have to vary some details. For example, Azure Cosmos DB client SDK will wrap this response up in an Exception with a RetryAfter property after making its own retries first. We’d love to see your final version!
This is documented in the Polly wiki here but I’ll aim to reference that also from the main Polly readme, to make it more discoverable. More info also in this similar question.
Let us know how you get on!
Thanks for the quick response, @reisenberger! Great library – I did not notice the provider overload until you pointed it out.
For posterity, here is an implementation of the method to obtain the header value as a TimeSpan (assumes server is in UTC):
Here’s the rest: