[PATCH] support for User-Agent tuning for wget (mime attached)

Csaba Henk csaba-ml at creo.hu
Tue Aug 29 21:16:57 UTC 2006


Hi,

I send the same "-U/--user-agent" patch here as earlier, but mime
attached this time.

I'm sorry for posting it as a separate thread -- I usually interact with
the list via Gmane, so I could post this as a followup only if I had a
newsreader which can do mime attachments. It's not the case now, and
installing/configuring one would be more hassle than it's worth for.

Csaba
-------------- next part --------------
Index: networking/wget.c
===================================================================
--- networking/wget.c	(revision 16010)
+++ networking/wget.c	(working copy)
@@ -132,6 +132,9 @@
 #define WGET_OPT_HEADER	16
 #define WGET_OPT_PREFIX	32
 #define WGET_OPT_PROXY	64
+#if ENABLE_FEATURE_WGET_USER_AGENT 
+#define WGET_OPT_USER_AGENT	128
+#endif
 
 #if ENABLE_FEATURE_WGET_LONG_OPTIONS
 static const struct option wget_long_options[] = {
@@ -142,6 +145,9 @@
 	{ "header",          1, NULL, 131 },
 	{ "directory-prefix",1, NULL, 'P' },
 	{ "proxy",           1, NULL, 'Y' },
+#if ENABLE_FEATURE_WGET_USER_AGENT
+	{ "user-agent",      1, NULL, 'U' },
+#endif
 	{ 0,                 0, 0, 0 }
 };
 #endif
@@ -172,6 +178,7 @@
 	int quiet_flag = FALSE;		/* Be verry, verry quiet...	    */
 	int use_proxy = 1;		/* Use proxies if env vars are set  */
 	char *proxy_flag = "on";	/* Use proxies if env vars are set  */
+	char *user_agent = "Wget"; /* Content of the "User-Agent" header field */
 
 	/*
 	 * Crack command line.
@@ -180,9 +187,15 @@
 #if ENABLE_FEATURE_WGET_LONG_OPTIONS
 	bb_applet_long_options = wget_long_options;
 #endif
+#if ENABLE_FEATURE_WGET_USER_AGENT
+	opt = bb_getopt_ulflags(argc, argv, "cq\213O:\203:P:Y:U:",
+					&fname_out, &headers_llist,
+					&dir_prefix, &proxy_flag, &user_agent);
+#else
 	opt = bb_getopt_ulflags(argc, argv, "cq\213O:\203:P:Y:",
 					&fname_out, &headers_llist,
 					&dir_prefix, &proxy_flag);
+#endif
 	if (opt & WGET_OPT_CONTINUE) {
 		++do_continue;
 	}
@@ -317,7 +330,8 @@
 				fprintf(sfp, "GET /%s HTTP/1.1\r\n", target.path);
 			}
 
-			fprintf(sfp, "Host: %s\r\nUser-Agent: Wget\r\n", target.host);
+			fprintf(sfp, "Host: %s\r\nUser-Agent: %s\r\n", target.host,
+			        user_agent);
 
 #ifdef CONFIG_FEATURE_WGET_AUTHENTICATION
 			if (target.user) {
Index: networking/Config.in
===================================================================
--- networking/Config.in	(revision 16010)
+++ networking/Config.in	(working copy)
@@ -698,6 +698,13 @@
 	help
 	  Support long options for the wget applet.
 
+config CONFIG_FEATURE_WGET_USER_AGENT
+	bool "Enable \"User-Agent\" tuning"
+	default n
+	depends on CONFIG_WGET
+	help
+	  Support for adjusting the "User-Agent" HTTP header field.
+
 config CONFIG_ZCIP
 	bool "zcip"
 	default n
Index: include/usage.h
===================================================================
--- include/usage.h	(revision 16010)
+++ include/usage.h	(working copy)
@@ -3396,7 +3396,8 @@
 
 #define wget_trivial_usage \
 	"[-c|--continue] [-q|--quiet] [-O|--output-document file]\n" \
-	"\t\t[--header 'header: value'] [-Y|--proxy on/off] [-P DIR] url"
+	"\t\t[--header 'header: value'] [-Y|--proxy on/off] [-P DIR]" \
+	USE_FEATURE_WGET_USER_AGENT("\n\t\t[-U|--user-agent agent]") " url"
 #define wget_full_usage \
 	"wget retrieves files via HTTP or FTP\n\n" \
 	"Options:\n" \
@@ -3404,6 +3405,7 @@
 	"\t-q\tquiet mode - do not print\n" \
 	"\t-P\tSet directory prefix to DIR\n" \
 	"\t-O\tsave to filename ('-' for stdout)\n" \
+	USE_FEATURE_WGET_USER_AGENT("\t-U\tadjust 'User-Agent' field\n") \
 	"\t-Y\tuse proxy ('on' or 'off')"
 
 #define which_trivial_usage \


More information about the busybox mailing list