Attached is a simple patch that adds --server-response
to wget. I am using it with HTTP only but there is
(partial) FTP support too.
Let me know what you think.
--
Stéphane
--- wget.c.orig 2016-10-07 10:47:12.000000000 -0400
+++ wget.c 2017-01-23 21:47:58.148903902 -0500
@@ -105,10 +105,10 @@
/* Since we ignore these opts, we don't show them in --help */
/* //usage: " [--no-check-certificate] [--no-cache] [--passive-ftp] [-t TRIES]" */
/* //usage: " [-nv] [-nc] [-nH] [-np]" */
-//usage: " [-U|--user-agent AGENT]" IF_FEATURE_WGET_TIMEOUT(" [-T SEC]") " URL..."
+//usage: " [-S|--server-response] [-U|--user-agent AGENT]" IF_FEATURE_WGET_TIMEOUT(" [-T SEC]") " URL..."
//usage: )
//usage: IF_NOT_FEATURE_WGET_LONG_OPTIONS(
-//usage: "[-cq] [-O FILE] [-Y on/off] [-P DIR] [-U AGENT]"
+//usage: "[-cq] [-O FILE] [-Y on/off] [-P DIR] [-S] [-U AGENT]"
//usage: IF_FEATURE_WGET_TIMEOUT(" [-T SEC]") " URL..."
//usage: )
//usage:#define wget_full_usage "\n\n"
@@ -119,6 +119,7 @@
//usage: "\n -c Continue retrieval of aborted transfer"
//usage: "\n -q Quiet"
//usage: "\n -P DIR Save to DIR (default .)"
+//usage: "\n -S Print server response"
//usage: IF_FEATURE_WGET_TIMEOUT(
//usage: "\n -T SEC Network read timeout is SEC seconds"
//usage: )
@@ -232,16 +233,17 @@
enum {
WGET_OPT_CONTINUE = (1 << 0),
WGET_OPT_QUIET = (1 << 1),
- WGET_OPT_OUTNAME = (1 << 2),
- WGET_OPT_PREFIX = (1 << 3),
- WGET_OPT_PROXY = (1 << 4),
- WGET_OPT_USER_AGENT = (1 << 5),
- WGET_OPT_NETWORK_READ_TIMEOUT = (1 << 6),
- WGET_OPT_RETRIES = (1 << 7),
- WGET_OPT_nsomething = (1 << 8),
- WGET_OPT_HEADER = (1 << 9) * ENABLE_FEATURE_WGET_LONG_OPTIONS,
- WGET_OPT_POST_DATA = (1 << 10) * ENABLE_FEATURE_WGET_LONG_OPTIONS,
- WGET_OPT_SPIDER = (1 << 11) * ENABLE_FEATURE_WGET_LONG_OPTIONS,
+ WGET_OPT_SERVER_RESPONSE = (1 << 2),
+ WGET_OPT_OUTNAME = (1 << 3),
+ WGET_OPT_PREFIX = (1 << 4),
+ WGET_OPT_PROXY = (1 << 5),
+ WGET_OPT_USER_AGENT = (1 << 6),
+ WGET_OPT_NETWORK_READ_TIMEOUT = (1 << 7),
+ WGET_OPT_RETRIES = (1 << 8),
+ WGET_OPT_nsomething = (1 << 9),
+ WGET_OPT_HEADER = (1 << 10) * ENABLE_FEATURE_WGET_LONG_OPTIONS,
+ WGET_OPT_POST_DATA = (1 << 11) * ENABLE_FEATURE_WGET_LONG_OPTIONS,
+ WGET_OPT_SPIDER = (1 << 12) * ENABLE_FEATURE_WGET_LONG_OPTIONS,
};
enum {
@@ -423,6 +425,8 @@
if (!s2)
s2 = "";
fprintf(fp, "%s%s\r\n", s1, s2);
+ if (option_mask32 & WGET_OPT_SERVER_RESPONSE)
+ printf("--> %s%s\n\n", s1, s2);
fflush(fp);
log_io("> %s%s", s1, s2);
}
@@ -431,6 +435,9 @@
fgets_and_trim(fp);
} while (!isdigit(G.wget_buf[0]) || G.wget_buf[3] != ' ');
+ if (option_mask32 & WGET_OPT_SERVER_RESPONSE)
+ printf("%s\n", G.wget_buf);
+
G.wget_buf[3] = '\0';
result = xatoi_positive(G.wget_buf);
G.wget_buf[3] = ' ';
@@ -530,6 +537,8 @@
/* end of the headers? */
if (G.wget_buf[0] == '\0')
return NULL;
+ if (option_mask32 & WGET_OPT_SERVER_RESPONSE)
+ printf(" %s\n", G.wget_buf);
/* convert the header name to lower case */
for (s = G.wget_buf; isalnum(*s) || *s == '-' || *s == '.' || *s == '_'; ++s) {
@@ -1109,6 +1118,8 @@
str = G.wget_buf;
str = skip_non_whitespace(str);
str = skip_whitespace(str);
+ if (option_mask32 & WGET_OPT_SERVER_RESPONSE)
+ printf(" %s\n", G.wget_buf);
// FIXME: no error check
// xatou wouldn't work: "200 OK"
status = atoi(str);
@@ -1289,6 +1300,7 @@
/* name, has_arg, val */
"continue\0" No_argument "c"
"quiet\0" No_argument "q"
+ "server-response\0" No_argument "S"
"output-document\0" Required_argument "O"
"directory-prefix\0" Required_argument "P"
"proxy\0" Required_argument "Y"
@@ -1331,7 +1343,7 @@
#endif
opt_complementary = "-1" /* at least one URL */
IF_FEATURE_WGET_LONG_OPTIONS(":\xff::"); /* --header is a list */
- getopt32(argv, "cqO:P:Y:U:T:+"
+ getopt32(argv, "cqSO:P:Y:U:T:+"
/*ignored:*/ "t:"
/*ignored:*/ "n::"
/* wget has exactly four -n<letter> opts, all of which we can ignore:
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox