diff options
| author | Hauke Mehrtens | 2026-04-23 22:14:17 +0000 |
|---|---|---|
| committer | Hauke Mehrtens | 2026-06-07 11:23:30 +0000 |
| commit | 5cb19466d076ad6c811a0d9aec016316be34c391 (patch) | |
| tree | aed78a65bb565bd1159e5ece8f2a773d591dd69d | |
| parent | 0ba1b8718be5a2c7e0049a5ed5486f0ffe81fc21 (diff) | |
| download | uclient-5cb19466d076ad6c811a0d9aec016316be34c391.tar.gz | |
uclient-fetch: reset redirect counter per request
The retry counter for HTTP redirects was a static local that was
incremented but never reset. After 10 redirects across the process
lifetime, no further URL could ever be redirected, including freshly
started requests when multiple URLs were passed on the command line.
Move the counter to file scope and reset it in init_request() so every
new request starts with a fresh redirect budget.
Assisted-by: Claude:claude-opus-4-7
Link: https://github.com/openwrt/uclient/pull/16
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
| -rw-r--r-- | uclient-fetch.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/uclient-fetch.c b/uclient-fetch.c index 43f7d9d..1ca2732 100644 --- a/uclient-fetch.c +++ b/uclient-fetch.c @@ -68,6 +68,7 @@ static char *auth_str; static char **urls; static int n_urls; static int timeout; +static int redirects; static bool resume, cur_resume; static LIST_HEAD(headers); @@ -182,9 +183,8 @@ static void header_done_cb(struct uclient *cl) }; struct blob_attr *tb[__H_MAX]; uint64_t resume_offset = 0, resume_end, resume_size; - static int retries; - if (retries < 10) { + if (redirects < 10) { int ret = uclient_http_redirect(cl); if (ret < 0) { if (!quiet) @@ -197,7 +197,7 @@ static void header_done_cb(struct uclient *cl) if (!quiet) fprintf(stderr, "Redirected to %s on %s\n", cl->url->location, cl->url->host); - retries++; + redirects++; return; } } @@ -335,6 +335,7 @@ static int init_request(struct uclient *cl) out_offset = 0; out_bytes = 0; out_len = 0; + redirects = 0; uclient_http_set_ssl_ctx(cl, ssl_ops, ssl_ctx, verify); if (timeout) |