I ran into a situation today in which I needed to disable HTTP
redirection processing (3xx status codes). A little digging in
the WGET sources revealed a hard-coded limit of 20 redirection
"hops" before giving up. The attached patch makes this value
configurable via the command line (--max-redirections=NUMBER)
or via wgetrc (max_redirections=NUMBER). Setting this value
to 0 disables redirections.
The default is still 20, so default behavior has not changed.
Please consider for inclusion, if you feel this might be useful.
KM
diff -uprN -x .svn wget.orig/doc/ChangeLog wget/doc/ChangeLog
--- wget.orig/doc/ChangeLog 2005-11-18 15:55:21.515625000 -0600
+++ wget/doc/ChangeLog 2005-11-18 16:53:22.000000000 -0600
@@ -1,3 +1,9 @@
+2005-11-18 Keith Moore <[EMAIL PROTECTED]>
+
+ * sample.wgetrc: Added max_redirections.
+
+ * wget.texi: Document max_redirections.
+
2005-11-15 Hrvoje Niksic <[EMAIL PROTECTED]>
* wget.texi: Document https_proxy.
diff -uprN -x .svn wget.orig/doc/sample.wgetrc wget/doc/sample.wgetrc
--- wget.orig/doc/sample.wgetrc 2005-09-04 05:01:47.000000000 -0500
+++ wget/doc/sample.wgetrc 2005-11-18 16:49:48.531250000 -0600
@@ -110,3 +110,10 @@ waitretry = 10
# To have Wget follow FTP links from HTML files by default, set this
# to on:
#follow_ftp = off
+
+# You can customize the maximum number of redirections Wget will
+# follow. The default (20) was chosen as a "reasonable" value,
+# which is low enough to not cause havoc, yet high enough to
+# guarantee that normal retrievals will not be hurt by the check.
+# Setting this value to 0 will disable redirections.
+# max_redirections=20
diff -uprN -x .svn wget.orig/doc/wget.texi wget/doc/wget.texi
--- wget.orig/doc/wget.texi 2005-11-18 15:55:21.531250000 -0600
+++ wget/doc/wget.texi 2005-11-18 17:03:26.359375000 -0600
@@ -1332,6 +1332,17 @@ the above will not work because @samp{--
them (and neither will browsers) and the @file{cookies.txt} file will
be empty. In that case use @samp{--keep-session-cookies} along with
@samp{--save-cookies} to force saving of session cookies.
+
[EMAIL PROTECTED] max redirections
[EMAIL PROTECTED] --max-redirections=NUMBER
+Sets the maximum number of redirections Wget will follow when
+processing a single request.
+
+The default (20) was chosen as a "reasonable" value, which is low
+enough to not cause havoc, yet high enough to guarantee that normal
+retrievals will not be hurt by the check.
+
+Setting this value to 0 disables redirections.
@end table
@node HTTPS (SSL/TLS) Options
diff -uprN -x .svn wget.orig/src/ChangeLog wget/src/ChangeLog
--- wget.orig/src/ChangeLog 2005-11-18 15:55:20.656250000 -0600
+++ wget/src/ChangeLog 2005-11-18 16:40:56.109375000 -0600
@@ -1,3 +1,15 @@
+2005-11-18 Keith Moore <[EMAIL PROTECTED]>
+
+ * init.c: Support --max-redirections=NUMBER on command-line and
+ max_redirections=NUMBER in wgetrc file.
+
+ * main.c: Ditto.
+
+ * options.h: Added opt.max_redirections option.
+
+ * retr.c: Honor new opt.max_redirections option instead of old
+ MAX_REDIRECTIONS constant.
+
2005-11-02 Mauro Tortonesi <[EMAIL PROTECTED]>
* Makefile.in: Removed support for unit testing (now it is in
diff -uprN -x .svn wget.orig/src/init.c wget/src/init.c
--- wget.orig/src/init.c 2005-08-15 17:49:38.000000000 -0500
+++ wget/src/init.c 2005-11-18 17:24:54.687500000 -0600
@@ -177,6 +177,7 @@ static struct {
{ "loadcookies", &opt.cookies_input, cmd_file },
{ "logfile", &opt.lfilename, cmd_file },
{ "login", &opt.ftp_user, cmd_string },/* deprecated*/
+ { "maxredirections", &opt.max_redirections, cmd_number },
{ "mirror", NULL, cmd_spec_mirror },
{ "netrc", &opt.netrc, cmd_boolean },
{ "noclobber", &opt.noclobber, cmd_boolean },
@@ -313,6 +314,8 @@ defaults (void)
opt.restrict_files_os = restrict_windows;
#endif
opt.restrict_files_ctrl = true;
+
+ opt.max_redirections = 20;
}
/* Return the user's home directory (strdup-ed), or NULL if none is
diff -uprN -x .svn wget.orig/src/main.c wget/src/main.c
--- wget.orig/src/main.c 2005-11-18 16:00:05.593750000 -0600
+++ wget/src/main.c 2005-11-18 17:26:35.093750000 -0600
@@ -187,6 +187,7 @@ static struct cmdline_option option_data
{ "level", 'l', OPT_VALUE, "reclevel", -1 },
{ "limit-rate", 0, OPT_VALUE, "limitrate", -1 },
{ "load-cookies", 0, OPT_VALUE, "loadcookies", -1 },
+ { "max-redirections", 0, OPT_VALUE, "maxredirections", -1 },
{ "mirror", 'm', OPT_BOOLEAN, "mirror", -1 },
{ "no", 'n', OPT__NO, NULL, required_argument },
{ "no-clobber", 0, OPT_BOOLEAN, "noclobber", -1 },
@@ -518,6 +519,8 @@ HTTP options:\n"),
--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_("\
+ --max-redirections=NUMBER set maximum redirections to NUMBER.\n"),
"\n",
#ifdef HAVE_SSL
diff -uprN -x .svn wget.orig/src/options.h wget/src/options.h
--- wget.orig/src/options.h 2005-08-15 17:49:38.000000000 -0500
+++ wget/src/options.h 2005-11-18 16:40:56.109375000 -0600
@@ -220,6 +220,8 @@ struct options
prefer_none
} prefer_family; /* preferred address family when more
than one type is available */
+
+ int max_redirections;
};
extern struct options opt;
diff -uprN -x .svn wget.orig/src/retr.c wget/src/retr.c
--- wget.orig/src/retr.c 2005-10-05 11:17:45.000000000 -0500
+++ wget/src/retr.c 2005-11-18 16:40:56.125000000 -0600
@@ -568,13 +568,6 @@ calc_rate (wgint bytes, double secs, int
return dlrate;
}
-/* Maximum number of allowed redirections. 20 was chosen as a
- "reasonable" value, which is low enough to not cause havoc, yet
- high enough to guarantee that normal retrievals will not be hurt by
- the check. */
-
-#define MAX_REDIRECTIONS 20
-
#define SUSPEND_POST_DATA do { \
post_data_suspended = true; \
saved_post_data = opt.post_data; \
@@ -748,10 +741,10 @@ retrieve_url (const char *origurl, char
mynewloc = xstrdup (newloc_parsed->url);
/* Check for max. number of redirections. */
- if (++redirection_count > MAX_REDIRECTIONS)
+ if (++redirection_count > opt.max_redirections)
{
logprintf (LOG_NOTQUIET, _("%d redirections exceeded.\n"),
- MAX_REDIRECTIONS);
+ opt.max_redirections);
url_free (newloc_parsed);
url_free (u);
xfree (url);
Files wget.orig/src/wget.exe and wget/src/wget.exe differ