brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: Retry-After tells clients how long to wait, and curl --retry obeys it

Curl
~/tips/tip-http-retry-after-curl-retry

Retry-After: 120

The Retry-After header sets how long a client should wait, and curl --retry follows it.

Rate limits and maintenance pages are annoying enough without a client that hammers the server again a second later. The Retry-After header exists to say how long to wait.

Retry-After: 120
Retry-After: Wed, 21 Oct 2015 07:28:00 GMT

MDN lists two forms: a number of seconds to wait after the response arrives, or an HTTP date after which to retry. It is used in three places. A 503 Service Unavailable says how long the service is expected to be down. A 429 Too Many Requests says how long to wait before asking again. A redirect such as 301 gives the minimum wait before the client follows it.

On the client side, curl has this built in:

curl --retry 5 https://example.com/api

According to the curl manual, --retry retries on transient errors, meaning a timeout or an HTTP 408, 429, 500, 502, 503 or 504. Between tries it waits one second first and doubles the wait each time, up to 10 minutes. And curl complies with the Retry-After header when one is present to know when to retry. That was added in curl 7.66.0.

Two related options: --retry-delay sets a fixed pause and so turns off the doubling, and --retry-max-time limits the total time allowed for retries.

The caveat is on the server side. MDN says support for the header is still inconsistent on clients and servers. Some crawlers, such as Googlebot, honor it, and sending it with a 503 helps search engines keep indexing your site once the downtime is over. I’d add it to any maintenance page I serve, but I would not rely on every client to listen.

Further reading: MDN: Retry-After, curl man page: –retry

More Curl tips curl --trace-ascii – https://example.com/ curl -fsS --fail-early \ url = "https://example.com/data/latest.json" curl -4 -s -o /dev/null -w '%{remote_ip} %{http_code}\n' https://example.com/ curl -q -fsS https://example.com/api/status All Curl tips (71) All topics

Link