From: Michael Tremer Date: Sat, 21 Jun 2025 11:45:35 +0000 (+0000) Subject: xfer: Add a function to set custom headers X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0eb07e15de1e27a546f800c7db724112aa575d1c;p=pakfire.git xfer: Add a function to set custom headers Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/xfer.c b/src/pakfire/xfer.c index d656c71a..f298cc31 100644 --- a/src/pakfire/xfer.c +++ b/src/pakfire/xfer.c @@ -578,6 +578,32 @@ char* pakfire_xfer_escape(struct pakfire_xfer* self, const char* s) { return result; } +int pakfire_xfer_add_header(struct pakfire_xfer* self, const char* format, ...) { + char* header = NULL; + va_list args; + int r; + + // Format the value + va_start(args, format); + r = vasprintf(&header, format, args); + va_end(args); + + // Break on error + if (r < 0) { + r = -errno; + goto ERROR; + } + + // Append the header + self->headers = curl_slist_append(self->headers, header); + +ERROR: + if (header) + free(header); + + return r; +} + int pakfire_xfer_add_query(struct pakfire_xfer* xfer, const char* key, const char* format, ...) { char* value = NULL; diff --git a/src/pakfire/xfer.h b/src/pakfire/xfer.h index 7ddb0100..f74e2832 100644 --- a/src/pakfire/xfer.h +++ b/src/pakfire/xfer.h @@ -113,6 +113,8 @@ int pakfire_xfer_verify_hashes(struct pakfire_xfer* self, const struct pakfire_h char* pakfire_xfer_escape(struct pakfire_xfer* self, const char* s); +int pakfire_xfer_add_header(struct pakfire_xfer* self, const char* format, ...) + __attribute__((format(printf, 2, 3))); int pakfire_xfer_add_query(struct pakfire_xfer* xfer, const char* key, const char* format, ...) __attribute__((format(printf, 3, 4))); int pakfire_xfer_add_param(struct pakfire_xfer* xfer,