pull-job: add interface for controlling Accept: header sent to http server

This commit is contained in:
Lennart Poettering
2025-11-05 16:48:46 +01:00
parent 41b0c68760
commit 4a886d9ab4
2 changed files with 44 additions and 13 deletions

View 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);
}

View 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);