diff options
author | Michael Vetter <jubalh@iodoru.org> | 2021-03-11 17:35:02 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-11 17:35:02 +0100 |
commit | 7d6f01df86631684fe80a3e73ece699cf061498b (patch) | |
tree | e28734730ffce8996bfb6d4be95e7a08790491cc /src/tools/http_upload.c | |
parent | 96580f917b5c0a061e7bf41714cf48c8e89cd5f8 (diff) | |
parent | e217ed0b798706fd11d19f1ffc0bdbbb95d55f53 (diff) | |
download | profani-tty-7d6f01df86631684fe80a3e73ece699cf061498b.tar.gz |
Merge pull request #1500 from mwuttke97/bugfix/1499
Fix HTTP upload
Diffstat (limited to 'src/tools/http_upload.c')
-rw-r--r-- | src/tools/http_upload.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/tools/http_upload.c b/src/tools/http_upload.c index fcdd582a..ff72e1b9 100644 --- a/src/tools/http_upload.c +++ b/src/tools/http_upload.c @@ -166,6 +166,10 @@ http_file_put(void* userdata) char* err = NULL; char* content_type_header; + // Optional headers + char* auth_header = NULL; + char* cookie_header = NULL; + char* expires_header = NULL; CURL* curl; CURLcode res; @@ -196,6 +200,21 @@ http_file_put(void* userdata) } headers = curl_slist_append(headers, content_type_header); headers = curl_slist_append(headers, "Expect:"); + + // Optional headers + if (upload->authorization) { + asprintf(&auth_header, "Authorization: %s", upload->authorization); + headers = curl_slist_append(headers, auth_header); + } + if (upload->cookie) { + asprintf(&cookie_header, "Cookie: %s", upload->cookie); + headers = curl_slist_append(headers, cookie_header); + } + if (upload->expires) { + asprintf(&expires_header, "Expires: %s", upload->expires); + headers = curl_slist_append(headers, expires_header); + } + curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); #if LIBCURL_VERSION_NUM >= 0x072000 @@ -225,6 +244,7 @@ http_file_put(void* userdata) curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)(upload->filesize)); curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); + if ((res = curl_easy_perform(curl)) != CURLE_OK) { err = strdup(curl_easy_strerror(res)); } else { @@ -252,11 +272,15 @@ http_file_put(void* userdata) curl_easy_cleanup(curl); curl_global_cleanup(); curl_slist_free_all(headers); + if (fh) { fclose(fh); } free(content_type_header); free(output.buffer); + free(auth_header); + free(cookie_header); + free(expires_header); pthread_mutex_lock(&lock); g_free(cert_path); @@ -334,6 +358,9 @@ http_file_put(void* userdata) free(upload->put_url); free(upload->alt_scheme); free(upload->alt_fragment); + free(upload->authorization); + free(upload->cookie); + free(upload->expires); free(upload); return NULL; |