summaryrefslogtreecommitdiff
path: root/src/process_url.c
diff options
context:
space:
mode:
authorMole Shang <[email protected]>2023-08-08 23:13:28 +0800
committerMole Shang <[email protected]>2023-08-08 23:13:28 +0800
commit66e17a6855dfa723b017ccd3685950c2de51f5da (patch)
tree32b8f44a134b61f2d906710a83ac1a87ff922b06 /src/process_url.c
parentcee1e6cc9bfb25b6630719045e15fbf0a3044069 (diff)
downloadhinata-66e17a6855dfa723b017ccd3685950c2de51f5da.tar.gz
hinata-66e17a6855dfa723b017ccd3685950c2de51f5da.tar.bz2
hinata-66e17a6855dfa723b017ccd3685950c2de51f5da.zip
process_url: expose get_info with a new param `p_content_type`
Diffstat (limited to 'src/process_url.c')
-rw-r--r--src/process_url.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/process_url.c b/src/process_url.c
index 7d04f37..a1204a1 100644
--- a/src/process_url.c
+++ b/src/process_url.c
@@ -244,7 +244,7 @@ static int parse_url(const char *URL, const char *outdir, char *fn) {
return 0;
}
-static bool get_info(const char *URL, long *psize) {
+bool get_info(const char *URL, long *psize, char **p_content_type) {
CURL *curl;
long resp_code;
bool support_range = false;
@@ -258,6 +258,16 @@ static bool get_info(const char *URL, long *psize) {
if (logerr(r)) {
goto end;
}
+ char *ct = NULL;
+ r = curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &ct);
+ if (logerr(r)) {
+ goto end;
+ }
+ DEBUG_PRINT("Content-Type: %s\n", ct);
+ if (p_content_type) {
+ *p_content_type = malloc(strlen(ct) + 1);
+ strcpy(*p_content_type, ct);
+ }
r = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD_T,
(curl_off_t *)psize);
if (logerr(r)) {
@@ -268,11 +278,6 @@ static bool get_info(const char *URL, long *psize) {
if (logerr(rh) || strcmp(pch->value, "bytes")) {
goto end;
}
- char *ct = NULL;
- r = curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &ct);
- if (logerr(r)) {
- goto end;
- }
support_range = true;
end:
@@ -387,7 +392,7 @@ static int download(curl_conf_t *curl_c) {
static thrd_info_t thrd_info[MAX_THREAD] = {0};
- bool support_range = get_info(curl_c->URL, &cl);
+ bool support_range = get_info(curl_c->URL, &cl, NULL);
DEBUG_PRINT("Size: %ld bytes.\n", cl);
if (support_range && cl > 0L) {
curl_c->dltotal = cl;