shared/curl-util: add curl_append_to_header
This commit is contained in:
+6
-12
@@ -1112,20 +1112,14 @@ static int context_acquire_data(Context *c) {
|
||||
if (!token_header)
|
||||
return context_log_oom(c);
|
||||
|
||||
struct curl_slist *n = curl_slist_append(c->request_header_data, token_header);
|
||||
if (!n)
|
||||
return context_log_oom(c);
|
||||
|
||||
c->request_header_data = n;
|
||||
r = curl_append_to_header(&c->request_header_data, STRV_MAKE(token_header));
|
||||
if (r < 0)
|
||||
return context_log_errno(c, LOG_ERR, r, "Failed to create curl header: %m");
|
||||
}
|
||||
|
||||
STRV_FOREACH(i, arg_extra_header) {
|
||||
struct curl_slist *n = curl_slist_append(c->request_header_data, *i);
|
||||
if (!n)
|
||||
return context_log_oom(c);
|
||||
|
||||
c->request_header_data = n;
|
||||
}
|
||||
r = curl_append_to_header(&c->request_header_data, arg_extra_header);
|
||||
if (r < 0)
|
||||
return context_log_errno(c, LOG_ERR, r, "Failed to create curl header: %m");
|
||||
|
||||
if (c->request_header_data)
|
||||
if (curl_easy_setopt(c->curl_data, CURLOPT_HTTPHEADER, c->request_header_data) != CURLE_OK)
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "hashmap.h"
|
||||
#include "log.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "time-util.h"
|
||||
#include "version.h"
|
||||
|
||||
@@ -407,3 +408,19 @@ int curl_parse_http_time(const char *t, usec_t *ret) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int curl_append_to_header(struct curl_slist **list, char **headers) {
|
||||
/* This function leaves 'list' modified on partial failure.
|
||||
* Input/output param list may point to NULL. */
|
||||
|
||||
assert(list);
|
||||
|
||||
STRV_FOREACH(h, headers) {
|
||||
struct curl_slist *l = curl_slist_append(*list, *h);
|
||||
if (!l)
|
||||
return -ENOMEM;
|
||||
*list = l;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -43,3 +43,4 @@ void curl_glue_remove_and_free(CurlGlue *g, CURL *c);
|
||||
struct curl_slist *curl_slist_new(const char *first, ...) _sentinel_;
|
||||
int curl_header_strdup(const void *contents, size_t sz, const char *field, char **value);
|
||||
int curl_parse_http_time(const char *t, usec_t *ret);
|
||||
int curl_append_to_header(struct curl_slist **list, char **headers);
|
||||
|
||||
Reference in New Issue
Block a user