]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
pull-job: keep track of content type reported by server
authorLennart Poettering <lennart@amutable.com>
Wed, 5 Nov 2025 15:47:59 +0000 (16:47 +0100)
committerLennart Poettering <lennart@amutable.com>
Thu, 19 Feb 2026 14:05:14 +0000 (15:05 +0100)
src/import/pull-job.c
src/import/pull-job.h

index e495b56eab299eb1b639db85bd03e0d4ac50b312..dca995543c8c66aed8fec3636b8b4086003a2a5d 100644 (file)
@@ -60,6 +60,7 @@ PullJob* pull_job_unref(PullJob *j) {
         iovec_done(&j->payload);
         iovec_done(&j->checksum);
         iovec_done(&j->expected_checksum);
+        free(j->content_type);
 
         return mfree(j);
 }
@@ -105,6 +106,7 @@ static int pull_job_restart(PullJob *j, const char *new_url) {
         iovec_done(&j->checksum);
         iovec_done(&j->expected_checksum);
         j->expected_content_length = UINT64_MAX;
+        j->content_type = mfree(j->content_type);
 
         curl_glue_remove_and_free(j->glue, j->curl);
         j->curl = NULL;
@@ -546,7 +548,7 @@ fail:
 }
 
 static size_t pull_job_header_callback(void *contents, size_t size, size_t nmemb, void *userdata) {
-        _cleanup_free_ char *length = NULL, *last_modified = NULL, *etag = NULL;
+        _cleanup_free_ char *length = NULL, *last_modified = NULL, *etag = NULL, *ct = NULL;
         size_t sz = size * nmemb;
         PullJob *j = ASSERT_PTR(userdata);
         CURLcode code;
@@ -630,6 +632,16 @@ static size_t pull_job_header_callback(void *contents, size_t size, size_t nmemb
                 return sz;
         }
 
+        r = curl_header_strdup(contents, sz, "Content-Type:", &ct);
+        if (r < 0) {
+                log_oom();
+                goto fail;
+        }
+        if (r > 0) {
+                free_and_replace(j->content_type, ct);
+                return sz;
+        }
+
         if (j->on_header) {
                 r = j->on_header(j, contents, sz);
                 if (r < 0)
index c4cda83a47ed5a92f5cca918545fead2c7f2f2af..d81f666d7a2c6f31ebb074678797f6415b369664 100644 (file)
@@ -67,6 +67,7 @@ typedef struct PullJob {
         struct stat disk_stat;
 
         usec_t mtime;
+        char *content_type;
 
         ImportCompress compress;