]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
pull-job: add interface for controlling Accept: header sent to http server
authorLennart Poettering <lennart@amutable.com>
Wed, 5 Nov 2025 15:48:46 +0000 (16:48 +0100)
committerLennart Poettering <lennart@amutable.com>
Thu, 19 Feb 2026 14:05:14 +0000 (15:05 +0100)
src/import/pull-job.c
src/import/pull-job.h

index dca995543c8c66aed8fec3636b8b4086003a2a5d..bd4211804249443268a519da784047c7de6f73df 100644 (file)
@@ -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);
+}
index d81f666d7a2c6f31ebb074678797f6415b369664..41dc5674285541583745e075cbb4a7e056bc9a92 100644 (file)
@@ -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);