From: Lennart Poettering Date: Wed, 5 Nov 2025 15:48:46 +0000 (+0100) Subject: pull-job: add interface for controlling Accept: header sent to http server X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4a886d9ab4999370556dbecda2def1c4dc41da11;p=thirdparty%2Fsystemd.git pull-job: add interface for controlling Accept: header sent to http server --- diff --git a/src/import/pull-job.c b/src/import/pull-job.c index dca995543c8..bd421180424 100644 --- a/src/import/pull-job.c +++ b/src/import/pull-job.c @@ -736,6 +736,27 @@ int pull_job_new( return 0; } +int pull_job_add_request_header(PullJob *j, const char *hdr) { + assert(j); + assert(hdr); + + if (j->request_header) { + struct curl_slist *l; + + l = curl_slist_append(j->request_header, hdr); + if (!l) + return -ENOMEM; + + j->request_header = l; + } else { + j->request_header = curl_slist_new(hdr, NULL); + if (!j->request_header) + return -ENOMEM; + } + + return 0; +} + int pull_job_begin(PullJob *j) { int r; @@ -759,19 +780,9 @@ int pull_job_begin(PullJob *j) { if (!hdr) return -ENOMEM; - if (!j->request_header) { - j->request_header = curl_slist_new(hdr, NULL); - if (!j->request_header) - return -ENOMEM; - } else { - struct curl_slist *l; - - l = curl_slist_append(j->request_header, hdr); - if (!l) - return -ENOMEM; - - j->request_header = l; - } + r = pull_job_add_request_header(j, hdr); + if (r < 0) + return r; } if (j->request_header) { @@ -808,3 +819,20 @@ int pull_job_begin(PullJob *j) { return 0; } + +int pull_job_set_accept(PullJob *j, char * const *l) { + assert(j); + + if (strv_isempty(l)) + return 0; + + _cleanup_free_ char *joined = strv_join(l, ", "); + if (!joined) + return -ENOMEM; + + _cleanup_free_ char *f = strjoin("Accept: ", joined); + if (!f) + return -ENOMEM; + + return pull_job_add_request_header(j, f); +} diff --git a/src/import/pull-job.h b/src/import/pull-job.h index d81f666d7a2..41dc5674285 100644 --- a/src/import/pull-job.h +++ b/src/import/pull-job.h @@ -94,4 +94,7 @@ void pull_job_curl_on_finished(CurlGlue *g, CURL *curl, CURLcode result); void pull_job_close_disk_fd(PullJob *j); +int pull_job_add_request_header(PullJob *j, const char *hdr); +int pull_job_set_accept(PullJob *j, char * const *l); + DEFINE_TRIVIAL_CLEANUP_FUNC(PullJob*, pull_job_unref);