How do I set the `Retry-After` header in a Cloudflare Worker when a rate limit is exceeded?

Responsive Ad Header

Question

Grade: Education Subject: Support
How do I set the `Retry-After` header in a Cloudflare Worker when a rate limit is exceeded?
Asked by:
91 Viewed 91 Answers

Answer (91)

Best Answer
(377)
When a rate limit is exceeded, you can set the `Retry-After` header in the Worker's response. This header tells the client how long to wait before retrying the request. The value can be a number of seconds or a specific date/time. For example: `response.headers.set('Retry-After', '60')` would tell the client to wait 60 seconds. Using a date/time is less common but possible.