pull-job: keep track of content type reported by server

This commit is contained in:
Lennart Poettering
2025-11-05 16:47:59 +01:00
parent dbf13060e1
commit 41b0c68760
2 changed files with 14 additions and 1 deletions

View 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)

View File

@@ -67,6 +67,7 @@ typedef struct PullJob {
struct stat disk_stat;
usec_t mtime;
char *content_type;
ImportCompress compress;