]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tool_cb_hdr: Fix --remote-header-name with schemeless URL
authorJay Satiro <raysatiro@yahoo.com>
Sun, 1 May 2016 20:07:04 +0000 (16:07 -0400)
committerJay Satiro <raysatiro@yahoo.com>
Sun, 1 May 2016 20:07:04 +0000 (16:07 -0400)
- Move the existing scheme check from tool_operate.

In the case of --remote-header-name we want to parse Content-disposition
for a filename, but only if the scheme is http or https. A recent
adjustment 0dc4d8e was made to account for schemeless URLs however it's
not 100% accurate. To remedy that I've moved the scheme check to the
header callback, since at that point the library has already determined
the scheme.

Bug: https://github.com/curl/curl/issues/760
Reported-by: Kai Noda
src/tool_cb_hdr.c
src/tool_operate.c

index 5be02aad2cc3a01335b9fc474f186f04bd3a1b58..f7d835562765fa8c3076d7cc1b2f6669286f4b0c 100644 (file)
@@ -48,6 +48,7 @@ size_t tool_header_cb(void *ptr, size_t size, size_t nmemb, void *userdata)
   const char *str = ptr;
   const size_t cb = size * nmemb;
   const char *end = (char*)ptr + cb;
+  char *url = NULL;
 
   /*
    * Once that libcurl has called back tool_header_cb() the returned value
@@ -88,7 +89,9 @@ size_t tool_header_cb(void *ptr, size_t size, size_t nmemb, void *userdata)
    */
 
   if(hdrcbdata->honor_cd_filename &&
-     (cb > 20) && checkprefix("Content-disposition:", str)) {
+     (cb > 20) && checkprefix("Content-disposition:", str) &&
+     !curl_easy_getinfo(outs->config->easy, CURLINFO_EFFECTIVE_URL, &url) &&
+     url && (checkprefix("http://", url) || checkprefix("https://", url))) {
     const char *p = str + 20;
 
     /* look for the 'filename=' parameter
index ab29c00b31ae9d818236ca1e020ab875c681806a..5f49efb713124edd2c852075602c30a021a620cd 100644 (file)
@@ -1295,12 +1295,7 @@ static CURLcode operate_do(struct GlobalConfig *global,
           my_setopt_flags(curl, CURLOPT_REDIR_PROTOCOLS, config->proto_redir);
 
         if(config->content_disposition
-           && (urlnode->flags & GETOUT_USEREMOTE)
-           && (checkprefix("http://", this_url) ||
-               checkprefix("https://", this_url) ||
-               (!strstr(this_url, "://") &&
-                (!config->proto_default ||
-                 checkprefix("http", config->proto_default)))))
+           && (urlnode->flags & GETOUT_USEREMOTE))
           hdrcbdata.honor_cd_filename = TRUE;
         else
           hdrcbdata.honor_cd_filename = FALSE;