[Toybox] [PATCH 1/1] Added basic post-data support
Moritz C. Weber
mo.c.weber at gmail.com
Sat Mar 26 09:59:04 PDT 2022
---
toys/pending/wget.c | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/toys/pending/wget.c b/toys/pending/wget.c
index bcb42f8d..ec25a9c8 100644
--- a/toys/pending/wget.c
+++ b/toys/pending/wget.c
@@ -26,7 +26,7 @@
* todo: Add support for Transfer Encoding (gzip|deflate)
* todo: Add support for RFC5987
-USE_WGET(NEWTOY(wget, "<1>1(max-redirect)#<0=20d(debug)O(output-document):", TOYFLAG_USR|TOYFLAG_BIN))
+USE_WGET(NEWTOY(wget, "<1>1(max-redirect)#<0=20d(debug)O(output-document):p(post-data):", TOYFLAG_USR|TOYFLAG_BIN))
config WGET
bool "wget"
@@ -36,6 +36,7 @@ config WGET
--max-redirect maximum redirections allowed
-d, --debug print lots of debugging information
-O, --output-document=FILE specify output filename
+ -p, --post-data=DATA send data in body of POST request
examples:
wget http://www.example.com
@@ -81,6 +82,7 @@ config WGET_OPENSSL
GLOBALS(
char *filename;
+ char *postdata;
long redirects;
int sock;
@@ -284,10 +286,17 @@ void wget_main(void)
if (TT.redirects < 0) error_exit("Too many redirects");
wget_info(TT.url, &host, &port, &path);
-
- sprintf(toybuf, "GET /%s HTTP/1.1\r\nHost: %s\r\n"
- "User-Agent: %s\r\nConnection: close\r\n\r\n",
- path, host, agent);
+ if (!FLAG(p)) {
+ sprintf(toybuf, "GET /%s HTTP/1.1\r\nHost: %s\r\n"
+ "User-Agent: %s\r\nConnection: close\r\n\r\n",
+ path, host, agent);
+ } else {
+ sprintf(toybuf, "POST /%s HTTP/1.1\r\nHost: %s\r\n"
+ "User-Agent: %s\r\nConnection: close\r\n"
+ "Content-Length: %ld\r\n\r\n"
+ "%s",
+ path, host, agent, sizeof(TT.postdata), TT.postdata);
+ }
if (FLAG(d)) printf("--- Request\n%s", toybuf);
wget_connect(host, port);
@@ -385,4 +394,4 @@ void wget_main(void)
exit:
wget_close();
free(TT.url);
-}
\ No newline at end of file
+}
--
2.20.1
More information about the Toybox
mailing list