From d66e3cc79a06cf02c972d76ba0f98cc2facf6ed2 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 7 Nov 2025 08:32:39 +0100 Subject: [PATCH] pull-job: make sure pull_job_restart() can be used to fetch the same resource again, just with new headers Let's flush out all response state from the job, but let's keep the request data previously configured, in particular the headers set. This is useful to re-request a resource, just with a slightly modified or identical URL. --- src/import/pull-job.c | 25 +++++++++++++++---------- src/import/pull-job.h | 2 ++ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/import/pull-job.c b/src/import/pull-job.c index 80197d6c57e..dcdb1fe8fa7 100644 --- a/src/import/pull-job.c +++ b/src/import/pull-job.c @@ -99,15 +99,19 @@ static void pull_job_finish(PullJob *j, int ret) { j->on_finished(j); } -static int pull_job_restart(PullJob *j, const char *new_url) { +int pull_job_restart(PullJob *j, const char *new_url) { int r; assert(j); - assert(new_url); - r = free_and_strdup(&j->url, new_url); - if (r < 0) - return r; + /* If an URL is specified we retry the same request, just towards a different URL. If the URL is NULL + * then we'll fire the same request again (which is useful if some parameters have been changed) */ + + if (new_url) { + r = free_and_strdup(&j->url, new_url); + if (r < 0) + return r; + } j->state = PULL_JOB_INIT; j->error = 0; @@ -119,16 +123,17 @@ static int pull_job_restart(PullJob *j, const char *new_url) { j->etag_exists = false; j->mtime = 0; iovec_done(&j->checksum); - iovec_done(&j->expected_checksum); - j->expected_content_length = UINT64_MAX; j->content_type = mfree(j->content_type); + if (new_url) { + /* Reset expectations if the URL changes */ + iovec_done(&j->expected_checksum); + j->expected_content_length = UINT64_MAX; + } + curl_glue_remove_and_free(j->glue, j->curl); j->curl = NULL; - curl_slist_free_all(j->request_header); - j->request_header = NULL; - import_compress_free(&j->compress); if (j->checksum_ctx) { diff --git a/src/import/pull-job.h b/src/import/pull-job.h index bfbdb8cced6..ea58b62f3bf 100644 --- a/src/import/pull-job.h +++ b/src/import/pull-job.h @@ -104,4 +104,6 @@ int pull_job_add_request_header(PullJob *j, const char *hdr); int pull_job_set_accept(PullJob *j, char * const *l); int pull_job_set_bearer_token(PullJob *j, const char *token); +int pull_job_restart(PullJob *j, const char *new_url); + DEFINE_TRIVIAL_CLEANUP_FUNC(PullJob*, pull_job_unref); -- 2.47.3