The --method allows to execute PUT,DELETE,OPTIONS. Usage sample:
$ busybox wget -O - -S -q --method=PUT \ --body-data="trololo" \ --header="Content-Type: text/plain" \ http://localhost:8080/cgi-bin/echo.sh HTTP/1.1 200 OK Content-Length: 7 Content-Type: text/html REQUEST_METHOD: PUT CONTENT_TYPE: text/plain CONTENT_LENGTH: trololo To avoid clashes with the --post-data/file options the --body-data/file must be used. But internally they stored to the same post_data and post_data fields. The GNU wget does similar. GNU wget shows an error on mutual usage of the options and we can do this too: if (option_mask32 & WGET_OPT_METHOD) { // the G.method already was populated from getopt() if (option_mask32 & WGET_OPT_POST) { bb_simple_error_msg_and_die("--method expects data through --body-data/file\n"); } But this bloats 331 bytes so let's just skip the error message. function old new delta static.wget_longopts 185 218 +33 packed_usage 2310 2331 +21 wget_main 2824 2841 +17 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 71/0) Total: 71 bytes text data bss dec hex filename 177452 3971 1688 183111 2cb47 busybox_old 177523 3971 1688 183182 2cb8e busybox_unstripped Signed-off-by: Sergey Ponomarev <stok...@gmail.com> --- networking/wget.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/networking/wget.c b/networking/wget.c index 0006f8807..9e7e16484 100644 --- a/networking/wget.c +++ b/networking/wget.c @@ -136,7 +136,9 @@ //usage:#define wget_trivial_usage //usage: IF_FEATURE_WGET_LONG_OPTIONS( //usage: "[-cqS] [--spider] [-O FILE] [-o LOGFILE] [--header STR]\n" -//usage: " [--post-data STR | --post-file FILE] [-Y on/off]\n" +//usage: " [--post-data=STR | --post-file=FILE]\n" +//usage: " [--method=METHOD] [--body-data=STR | --body-file=FILE]\n" +//usage: " [-Y on/off]\n" /* Since we ignore these opts, we don't show them in --help */ /* //usage: " [--no-cache] [--passive-ftp] [-t TRIES]" */ /* //usage: " [-nv] [-nc] [-nH] [-np]" */ @@ -303,6 +305,9 @@ enum { WGET_OPT_SPIDER = (1 << 13) * ENABLE_FEATURE_WGET_LONG_OPTIONS, WGET_OPT_NO_CHECK_CERT = (1 << 14) * ENABLE_FEATURE_WGET_LONG_OPTIONS, WGET_OPT_POST_FILE = (1 << 15) * ENABLE_FEATURE_WGET_LONG_OPTIONS, + WGET_OPT_METHOD = (1 << 16) * ENABLE_FEATURE_WGET_LONG_OPTIONS, + WGET_OPT_BODY_DATA = (1 << 17) * ENABLE_FEATURE_WGET_LONG_OPTIONS, + WGET_OPT_BODY_FILE = (1 << 18) * ENABLE_FEATURE_WGET_LONG_OPTIONS, /* hijack this bit for other than opts purposes: */ WGET_NO_FTRUNCATE = (1 << 31) }; @@ -1260,7 +1265,7 @@ static void download_one_url(const char *url) fputs(G.extra_headers, sfp); } - if (option_mask32 & WGET_OPT_POST_FILE) { + if (option_mask32 & WGET_OPT_POST_FILE || option_mask32 & WGET_OPT_BODY_FILE) { int fd = xopen_stdin(G.post_file); G.post_data = xmalloc_read(fd, NULL); close(fd); @@ -1515,6 +1520,9 @@ IF_DESKTOP( "tries\0" Required_argument "t") "spider\0" No_argument "\xfd" "no-check-certificate\0" No_argument "\xfc" "post-file\0" Required_argument "\xfb" + "method\0" Required_argument "\xf1" + "body-data\0" Required_argument "\xf2" + "body-file\0" Required_argument "\xf3" /* Ignored (we always use PASV): */ IF_DESKTOP( "passive-ftp\0" No_argument "\xf0") /* Ignored (we don't support caching) */ @@ -1571,6 +1579,9 @@ IF_DESKTOP( "no-parent\0" No_argument "\xf0") IF_FEATURE_WGET_LONG_OPTIONS(, &headers_llist) IF_FEATURE_WGET_LONG_OPTIONS(, &G.post_data) IF_FEATURE_WGET_LONG_OPTIONS(, &G.post_file) + IF_FEATURE_WGET_LONG_OPTIONS(, &G.method) + IF_FEATURE_WGET_LONG_OPTIONS(, &G.post_data) // body-data will be stored to post_data + IF_FEATURE_WGET_LONG_OPTIONS(, &G.post_file) // body-file will be stored to post_file ); #if 0 /* option bits debug */ if (option_mask32 & WGET_OPT_RETRIES) bb_error_msg("-t NUM"); @@ -1580,11 +1591,16 @@ IF_DESKTOP( "no-parent\0" No_argument "\xf0") if (option_mask32 & WGET_OPT_SPIDER) bb_error_msg("--spider"); if (option_mask32 & WGET_OPT_NO_CHECK_CERT) bb_error_msg("--no-check-certificate"); if (option_mask32 & WGET_OPT_POST_FILE) bb_error_msg("--post-file"); + if (option_mask32 & WGET_OPT_METHOD) bb_error_msg("--method"); + if (option_mask32 & WGET_OPT_BODY_DATA) bb_error_msg("--body-data"); + if (option_mask32 & WGET_OPT_BODY_FILE) bb_error_msg("--body-file"); exit(0); #endif argv += optind; - if (option_mask32 & WGET_OPT_POST) { + if (option_mask32 & WGET_OPT_METHOD) { + // the G.method already was populated from getopt() + } else if (option_mask32 & WGET_OPT_POST) { G.method = "POST"; } else if (option_mask32 & WGET_OPT_SPIDER) { /* Note: GNU wget --spider sends a HEAD and if it failed repeats with a GET */ -- 2.34.1 _______________________________________________ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox