res = -2;
goto out;
}
- if (opt.verbose)
+ if (progress)
progress_update (progress, sz, 0);
}
last_dltime = dltime;
}
- if (opt.verbose)
+ if (progress)
progress_update (progress, res, dltime);
*len += res;
}
res = -1;
out:
- if (opt.verbose)
+ if (progress)
progress_finish (progress, dltime);
if (elapsed)
*elapsed = dltime;
#define MAX_REDIRECTIONS 20
+#define SUSPEND_POST_DATA do { \
+ post_data_suspended = 1; \
+ saved_post_data = opt.post_data; \
+ saved_post_file_name = opt.post_file_name; \
+ opt.post_data = NULL; \
+ opt.post_file_name = NULL; \
+} while (0)
+
+#define RESTORE_POST_DATA do { \
+ if (post_data_suspended) \
+ { \
+ opt.post_data = saved_post_data; \
+ opt.post_file_name = saved_post_file_name; \
+ post_data_suspended = 0; \
+ } \
+} while (0)
+
/* Retrieve the given URL. Decides which loop to call -- HTTP, FTP,
FTP, proxy, etc. */
+/* #### This function should be rewritten so it doesn't return from
+ multiple points. */
+
uerr_t
retrieve_url (const char *origurl, char **file, char **newloc,
const char *refurl, int *dt)
char *local_file;
int redirection_count = 0;
+ int post_data_suspended = 0;
+ char *saved_post_data;
+ char *saved_post_file_name;
+
/* If dt is NULL, just ignore it. */
if (!dt)
dt = &dummy;
logprintf (LOG_NOTQUIET, _("Error parsing proxy URL %s: %s.\n"),
proxy, url_error (up_error_code));
xfree (url);
+ RESTORE_POST_DATA;
return PROXERR;
}
if (proxy_url->scheme != SCHEME_HTTP && proxy_url->scheme != u->scheme)
logprintf (LOG_NOTQUIET, _("Error in proxy URL %s: Must be HTTP.\n"), proxy);
url_free (proxy_url);
xfree (url);
+ RESTORE_POST_DATA;
return PROXERR;
}
}
url_free (u);
xfree (url);
xfree (mynewloc);
+ RESTORE_POST_DATA;
return result;
}
url_free (u);
xfree (url);
xfree (mynewloc);
+ RESTORE_POST_DATA;
return WRONGCODE;
}
url = mynewloc;
url_free (u);
u = newloc_parsed;
+
+ /* If we're being redirected from POST, we don't want to POST
+ again. Many requests answer POST with a redirection to an
+ index page; that redirection is clearly a GET. We "suspend"
+ POST data for the duration of the redirections, and restore
+ it when we're done. */
+ if (!post_data_suspended)
+ SUSPEND_POST_DATA;
+
goto redirected;
}
}
++global_download_count;
+ RESTORE_POST_DATA;
return result;
}