]> git.ipfire.org Git - pakfire.git/commitdiff
xfer: Add a function to set custom headers
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 21 Jun 2025 11:45:35 +0000 (11:45 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 21 Jun 2025 11:45:35 +0000 (11:45 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/xfer.c
src/pakfire/xfer.h

index d656c71a82f5f849e73ae00caa931b5c2846d868..f298cc3141bcf7423c893f3e423e71de8b3b5638 100644 (file)
@@ -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;
index 7ddb01005e1c60736eb5cd97250486d6cc8e2fe7..f74e28324aca6f40acd05e1ed874a42a112a49cd 100644 (file)
@@ -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,