[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: [PATCH] wget: custom Content-Type for --post-data and --post-file
From: Ildar Shaimordanov <ildar.shaimordanov () gmail ! com>
Date: 2021-10-18 18:02:26
Message-ID: CAN_got2Avzfz53Due7fcThTjsMpMtJS=itrjngj2kYQETjXWYg () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
Allow end-users to customize Content-Type for --post-data and --post-file.
More explanation in this PR:
https://github.com/rmyorston/busybox-w32/pull/233
The real use-case:
wget https://api.github.com/markdown/raw --header "Content-Type: text/plain"
Signed-off-by: Ildar Shaimordanov <ildar.shaimordanov@gmail.com>
---
networking/wget.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/networking/wget.c b/networking/wget.c
index 91ef99eab..789979c1a 100644
--- a/networking/wget.c
+++ b/networking/wget.c
@@ -213,6 +213,7 @@ enum {
HDR_RANGE = (1<<2),
HDR_AUTH = (1<<3) * ENABLE_FEATURE_WGET_AUTHENTICATION,
HDR_PROXY_AUTH = (1<<4) * ENABLE_FEATURE_WGET_AUTHENTICATION,
+ HDR_CONTENT_TYPE = (1<<5),
};
static const char wget_user_headers[] ALIGN1 =
"Host:\0"
@@ -222,18 +223,21 @@ static const char wget_user_headers[] ALIGN1 =
"Authorization:\0"
"Proxy-Authorization:\0"
# endif
+ "Content-Type:\0"
;
# define USR_HEADER_HOST (G.user_headers & HDR_HOST)
# define USR_HEADER_USER_AGENT (G.user_headers & HDR_USER_AGENT)
# define USR_HEADER_RANGE (G.user_headers & HDR_RANGE)
# define USR_HEADER_AUTH (G.user_headers & HDR_AUTH)
# define USR_HEADER_PROXY_AUTH (G.user_headers & HDR_PROXY_AUTH)
+# define USR_HEADER_CONTENT_TYPE (G.user_headers & HDR_CONTENT_TYPE)
#else /* No long options, no user-headers :( */
# define USR_HEADER_HOST 0
# define USR_HEADER_USER_AGENT 0
# define USR_HEADER_RANGE 0
# define USR_HEADER_AUTH 0
# define USR_HEADER_PROXY_AUTH 0
+# define USR_HEADER_CONTENT_TYPE 0
#endif
/* Globals */
@@ -1261,8 +1265,13 @@ static void download_one_url(const char *url)
}
if (G.post_data) {
+ /* Don't overwrite the user-specified header */
+ if (!USR_HEADER_CONTENT_TYPE) {
+ SENDFMT(sfp,
+ "Content-Type: application/x-www-form-urlencoded\r\n"
+ );
+ }
SENDFMT(sfp,
- "Content-Type: application/x-www-form-urlencoded\r\n"
"Content-Length: %u\r\n"
"\r\n"
"%s",
--
2.28.0
[Attachment #5 (text/html)]
<div dir="ltr">Allow end-users to customize Content-Type for --post-data and \
--post-file.<br><br>More explanation in this PR: <a \
href="https://github.com/rmyorston/busybox-w32/pull/233">https://github.com/rmyorston/busybox-w32/pull/233</a><br><br>The \
real use-case:<br>wget <a \
href="https://api.github.com/markdown/raw">https://api.github.com/markdown/raw</a> \
--header "Content-Type: text/plain"<br><br>Signed-off-by: Ildar \
Shaimordanov <<a href="mailto:ildar.shaimordanov@gmail.com">ildar.shaimordanov@gmail.com</a>><br>---<br> \
networking/wget.c | 11 ++++++++++-<br> 1 file changed, 10 insertions(+), 1 \
deletion(-)<br><br>diff --git a/networking/wget.c b/networking/wget.c<br>index \
91ef99eab..789979c1a 100644<br>--- a/networking/wget.c<br>+++ \
b/networking/wget.c<br>@@ -213,6 +213,7 @@ enum {<br> HDR_RANGE = \
(1<<2),<br> HDR_AUTH = (1<<3) * \
ENABLE_FEATURE_WGET_AUTHENTICATION,<br> HDR_PROXY_AUTH = (1<<4) * \
ENABLE_FEATURE_WGET_AUTHENTICATION,<br>+ HDR_CONTENT_TYPE = (1<<5),<br> \
};<br> static const char wget_user_headers[] ALIGN1 =<br> \
"Host:\0"<br>@@ -222,18 +223,21 @@ static const char wget_user_headers[] \
ALIGN1 =<br> "Authorization:\0"<br> \
"Proxy-Authorization:\0"<br> # endif<br>+ "Content-Type:\0"<br> \
;<br> # define USR_HEADER_HOST (G.user_headers & HDR_HOST)<br> # \
define USR_HEADER_USER_AGENT (G.user_headers & HDR_USER_AGENT)<br> # define \
USR_HEADER_RANGE (G.user_headers & HDR_RANGE)<br> # define \
USR_HEADER_AUTH (G.user_headers & HDR_AUTH)<br> # define \
USR_HEADER_PROXY_AUTH (G.user_headers & HDR_PROXY_AUTH)<br>+# define \
USR_HEADER_CONTENT_TYPE (G.user_headers & HDR_CONTENT_TYPE)<br> #else /* No long \
options, no user-headers :( */<br> # define USR_HEADER_HOST 0<br> # define \
USR_HEADER_USER_AGENT 0<br> # define USR_HEADER_RANGE 0<br> # define \
USR_HEADER_AUTH 0<br> # define USR_HEADER_PROXY_AUTH 0<br>+# define \
USR_HEADER_CONTENT_TYPE 0<br> #endif<br> <br> /* Globals */<br>@@ -1261,8 +1265,13 \
@@ static void download_one_url(const char *url)<br> }<br> <br> if \
(G.post_data) {<br>+ /* Don't overwrite the user-specified header */<br>+ if \
(!USR_HEADER_CONTENT_TYPE) {<br>+ SENDFMT(sfp,<br>+ "Content-Type: \
application/x-www-form-urlencoded\r\n"<br>+ );<br>+ }<br> \
SENDFMT(sfp,<br>- "Content-Type: \
application/x-www-form-urlencoded\r\n"<br> "Content-Length: \
%u\r\n"<br> "\r\n"<br> "%s",<br>-- \
<br>2.28.0<br><br><br></div>
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic