From: Lennart Poettering Date: Wed, 5 Nov 2025 15:47:59 +0000 (+0100) Subject: pull-job: keep track of content type reported by server X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=41b0c68760082db809a203174d3dc3ce366d867e;p=thirdparty%2Fsystemd.git pull-job: keep track of content type reported by server --- diff --git a/src/import/pull-job.c b/src/import/pull-job.c index e495b56eab2..dca995543c8 100644 --- a/src/import/pull-job.c +++ b/src/import/pull-job.c @@ -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) diff --git a/src/import/pull-job.h b/src/import/pull-job.h index c4cda83a47e..d81f666d7a2 100644 --- a/src/import/pull-job.h +++ b/src/import/pull-job.h @@ -67,6 +67,7 @@ typedef struct PullJob { struct stat disk_stat; usec_t mtime; + char *content_type; ImportCompress compress;