diff -urd wget-1.10/src/http.c wget-1.10.NEW/src/http.c --- wget-1.10/src/http.c 2005-05-30 17:29:01.000000000 +0300 +++ wget-1.10.NEW/src/http.c 2005-09-17 22:38:20.000000000 +0300 @@ -1081,6 +1081,7 @@ char *remote_time; /* remote time-stamp string */ char *error; /* textual HTTP error */ int statcode; /* status code */ + int force_local; wgint rd_size; /* amount of data read from socket */ double dltime; /* time it took to download the data */ const char *referer; /* value of the referer header. */ @@ -1713,6 +1714,25 @@ } hs->newloc = resp_header_strdup (resp, "Location"); hs->remote_time = resp_header_strdup (resp, "Last-Modified"); + + if (opt.obey_contdisp && !hs->force_local) + { + char *tmphdr = resp_header_strdup (resp, "Content-Disposition"); + if (tmphdr) + { + char *tmp2, *tmp = strstr(tmphdr, "filename="); + if (tmp) + { + tmp += 9; + tmp2 = tmp; + while (*tmp2 && (*tmp2 != ';')) tmp2++; + *tmp2 = '\0'; + + *hs->local_file = xstrdup(tmp); + } + xfree_null(tmphdr); + } + } /* Handle (possibly multiple instances of) the Set-Cookie header. */ { @@ -2031,6 +2051,7 @@ locf = opt.output_document; hstat.referer = referer; + hstat.force_local = 0; filename_len = strlen (*hstat.local_file); filename_plus_orig_suffix = alloca (filename_len + sizeof (".orig")); @@ -2198,6 +2219,8 @@ printwhat (count, opt.ntry); if (err == FOPEN_EXCL_ERR) { + hstat.force_local = 1; + /* Re-determine the file name. */ if (local_file && *local_file) { diff -urd wget-1.10/src/init.c wget-1.10.NEW/src/init.c --- wget-1.10/src/init.c 2005-05-30 16:31:23.000000000 +0300 +++ wget-1.10.NEW/src/init.c 2005-09-17 21:20:49.000000000 +0300 @@ -191,6 +191,7 @@ { "noparent", &opt.no_parent, cmd_boolean }, { "noproxy", &opt.no_proxy, cmd_vector }, { "numtries", &opt.ntry, cmd_number_inf },/* deprecated*/ + { "obeycontdisp", &opt.obey_contdisp, cmd_boolean }, { "outputdocument", &opt.output_document, cmd_file }, { "pagerequisites", &opt.page_requisites, cmd_boolean }, { "passiveftp", &opt.ftp_pasv, cmd_lockable_boolean }, diff -urd wget-1.10/src/main.c wget-1.10.NEW/src/main.c --- wget-1.10/src/main.c 2005-05-06 18:50:50.000000000 +0300 +++ wget-1.10.NEW/src/main.c 2005-09-17 22:23:12.000000000 +0300 @@ -218,6 +218,7 @@ { "no-parent", 0, OPT_BOOLEAN, "noparent", -1 }, { "output-document", 'O', OPT_VALUE, "outputdocument", -1 }, { "output-file", 'o', OPT_VALUE, "logfile", -1 }, + { "obey-cont-disp", 0, OPT_BOOLEAN, "obeycontdisp", -1 }, { "page-requisites", 'p', OPT_BOOLEAN, "pagerequisites", -1 }, { "parent", 0, OPT__PARENT, NULL, optional_argument }, { "passive-ftp", 0, OPT_BOOLEAN, "passiveftp", -1 }, @@ -541,6 +542,8 @@ --post-data=STRING use the POST method; send STRING as the data.\n"), N_("\ --post-file=FILE use the POST method; send contents of FILE.\n"), + N_("\ + --obey-cont-disp obey Content-Disposition header's filename.\n"), "\n", #ifdef HAVE_SSL diff -urd wget-1.10/src/options.h wget-1.10.NEW/src/options.h --- wget-1.10/src/options.h 2005-04-28 00:30:22.000000000 +0300 +++ wget-1.10.NEW/src/options.h 2005-09-17 21:16:47.000000000 +0300 @@ -145,6 +145,8 @@ generated by FTP? */ int htmlify; /* Do we HTML-ify the OS-dependent listings? */ + int obey_contdisp; /* Obey the "Content-Disposition" + header's filename field */ char *dot_style; wgint dot_bytes; /* How many bytes in a printing