mirror of
https://github.com/systemd/systemd.git
synced 2026-08-12 22:17:19 +00:00
pull-job: add interface for controlling Accept: header sent to http server
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user