From b9fba185c570b52fccffa2b9ae39ba32a0860daf Mon Sep 17 00:00:00 2001 From: Ildar Shaimordanov Date: Sun, 12 Dec 2021 03:19:13 +0100 Subject: [PATCH] wget: 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" function old new delta wget_main 2560 2581 +21 wget_user_headers 62 76 +14 .rodata 104196 104197 +1 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 36/0) Total: 36 bytes Signed-off-by: Ildar Shaimordanov Signed-off-by: Denys Vlasenko --- networking/wget.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/networking/wget.c b/networking/wget.c index 91ef99eab..9ec0e67b9 100644 --- a/networking/wget.c +++ b/networking/wget.c @@ -211,29 +211,33 @@ enum { HDR_HOST = (1<<0), HDR_USER_AGENT = (1<<1), 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<<3), + HDR_AUTH = (1<<4) * ENABLE_FEATURE_WGET_AUTHENTICATION, + HDR_PROXY_AUTH = (1<<5) * ENABLE_FEATURE_WGET_AUTHENTICATION, }; static const char wget_user_headers[] ALIGN1 = "Host:\0" "User-Agent:\0" "Range:\0" + "Content-Type:\0" # if ENABLE_FEATURE_WGET_AUTHENTICATION "Authorization:\0" "Proxy-Authorization:\0" # endif ; -# 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_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_CONTENT_TYPE (G.user_headers & HDR_CONTENT_TYPE) +# define USR_HEADER_AUTH (G.user_headers & HDR_AUTH) +# define USR_HEADER_PROXY_AUTH (G.user_headers & HDR_PROXY_AUTH) #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_HOST 0 +# define USR_HEADER_USER_AGENT 0 +# define USR_HEADER_RANGE 0 +# define USR_HEADER_CONTENT_TYPE 0 +# define USR_HEADER_AUTH 0 +# define USR_HEADER_PROXY_AUTH 0 #endif /* Globals */ @@ -1261,8 +1265,13 @@ static void download_one_url(const char *url) } if (G.post_data) { + /* If user did not override it... */ + 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",