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.
This commit is contained in:
Lennart Poettering
2026-02-19 15:05:15 +01:00
parent 93915ec17a
commit d66e3cc79a
2 changed files with 17 additions and 10 deletions
+15 -10
View File
@@ -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) {
+2
View File
@@ -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);