diff options
author | Jeremie Courreges-Anglas <jca@cvs.openbsd.org> | 2019-10-09 16:43:23 +0000 |
---|---|---|
committer | Jeremie Courreges-Anglas <jca@cvs.openbsd.org> | 2019-10-09 16:43:23 +0000 |
commit | b10b9585ae4a964ae1edecb6864063de441e8207 (patch) | |
tree | ff18615ab4f3923babb0fc397e9a1707bda67486 /usr.bin | |
parent | a1430cb52bc5ae408c6810e6be627b1733fc07a9 (diff) |
On a 503, only retry if "Retry-After: 0" is present.
We just bail out if the header is absent or if the server tells us to
wait. Prodding from job@, ok sthen@ deraadt@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/ftp/fetch.c | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/usr.bin/ftp/fetch.c b/usr.bin/ftp/fetch.c index ad7f4b733e2..552eaee2fe1 100644 --- a/usr.bin/ftp/fetch.c +++ b/usr.bin/ftp/fetch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fetch.c,v 1.171 2019/10/05 20:54:20 jca Exp $ */ +/* $OpenBSD: fetch.c,v 1.172 2019/10/09 16:43:22 jca Exp $ */ /* $NetBSD: fetch.c,v 1.14 1997/08/18 10:20:20 lukem Exp $ */ /*- @@ -186,6 +186,7 @@ url_get(const char *origline, const char *proxyenv, const char *outfile, int las char *hosttail, *cause = "unknown", *newline, *host, *port, *buf = NULL; char *epath, *redirurl, *loctail, *h, *p; int error, i, isftpurl = 0, isfileurl = 0, isredirect = 0, rval = -1; + int isunavail = 0, retryafter = -1; struct addrinfo hints, *res0, *res; const char * volatile savefile; char * volatile proxyurl = NULL; @@ -823,14 +824,8 @@ noslash: goto cleanup_url_get; #endif /* !SMALL */ case 503: - if (retried++) { - warnx("Error retrieving file: %s", cp); - goto cleanup_url_get; - } - if (verbose) - fprintf(ttyout, "Retrying %s\n", origline); - rval = url_get(origline, proxyenv, savefile, lastfile); - goto cleanup_url_get; + isunavail = 1; + break; default: warnx("Error retrieving file: %s", cp); goto cleanup_url_get; @@ -935,10 +930,32 @@ noslash: rval = url_get(redirurl, proxyenv, savefile, lastfile); free(redirurl); goto cleanup_url_get; +#define RETRYAFTER "Retry-After: " + } else if (isunavail && + strncasecmp(cp, RETRYAFTER, sizeof(RETRYAFTER) - 1) == 0) { + size_t s; + cp += sizeof(RETRYAFTER) - 1; + if ((s = strcspn(cp, " \t"))) + cp[s] = '\0'; + retryafter = strtonum(cp, 0, 0, &errstr); + if (errstr != NULL) + retryafter = -1; } free(buf); } + if (isunavail) { + if (retried || retryafter != 0) + warnx("Error retrieving file: 503 Service Unavailable"); + else { + if (verbose) + fprintf(ttyout, "Retrying %s\n", origline); + retried = 1; + rval = url_get(origline, proxyenv, savefile, lastfile); + } + goto cleanup_url_get; + } + /* Open the output file. */ if (!pipeout) { #ifndef SMALL |