[PATCH] uclient-fetch: add option to pass a custom Content-Type
pfzim at mail.ru
pfzim at mail.ru
Mon Nov 2 14:29:44 EST 2020
From: "Dmitry V. Zimin" <pfzim at mail.ru>
This patch add the option --post-type to pass a custom Content-Type
Signed-off-by: Dmitry V. Zimin <pfzim at mail.ru>
---
uclient-fetch.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/uclient-fetch.c b/uclient-fetch.c
index 061f0fd..ac257e2 100644
--- a/uclient-fetch.c
+++ b/uclient-fetch.c
@@ -44,6 +44,7 @@
static const char *user_agent = "uclient-fetch";
static const char *post_data;
static const char *post_file;
+static const char *post_type;
static struct ustream_ssl_ctx *ssl_ctx;
static const struct ustream_ssl_ops *ssl_ops;
static int quiet = false;
@@ -345,13 +346,13 @@ static int init_request(struct uclient *cl)
check_resume_offset(cl);
if (post_data) {
- uclient_http_set_header(cl, "Content-Type", "application/x-www-form-urlencoded");
+ uclient_http_set_header(cl, "Content-Type", post_type ? post_type : "application/x-www-form-urlencoded");
uclient_write(cl, post_data, strlen(post_data));
}
else if(post_file)
{
FILE *input_file;
- uclient_http_set_header(cl, "Content-Type", "application/x-www-form-urlencoded");
+ uclient_http_set_header(cl, "Content-Type", post_type ? post_type : "application/x-www-form-urlencoded");
input_file = fopen(post_file, "r");
if (!input_file)
@@ -480,8 +481,9 @@ static int usage(const char *progname)
" --user=<user> HTTP authentication username\n"
" --password=<password> HTTP authentication password\n"
" --user-agent|-U <str> Set HTTP user agent\n"
- " --post-data=STRING use the POST method; send STRING as the data\n"
- " --post-file=FILE use the POST method; send FILE as the data\n"
+ " --post-data=STRING Use the POST method; send STRING as the data\n"
+ " --post-file=FILE Use the POST method; send FILE as the data\n"
+ " --post-type=STRING Set custom Content-Type for POST method\n"
" --spider|-s Spider mode - only check file existence\n"
" --timeout=N|-T N Set connect/request timeout to N seconds\n"
" --proxy=on|off|-Y on|off Enable/disable env var configured proxy\n"
@@ -539,6 +541,7 @@ enum {
L_USER_AGENT,
L_POST_DATA,
L_POST_FILE,
+ L_POST_TYPE,
L_SPIDER,
L_TIMEOUT,
L_CONTINUE,
@@ -556,6 +559,7 @@ static const struct option longopts[] = {
[L_USER_AGENT] = { "user-agent", required_argument },
[L_POST_DATA] = { "post-data", required_argument },
[L_POST_FILE] = { "post-file", required_argument },
+ [L_POST_TYPE] = { "post-type", required_argument },
[L_SPIDER] = { "spider", no_argument },
[L_TIMEOUT] = { "timeout", required_argument },
[L_CONTINUE] = { "continue", no_argument },
@@ -625,6 +629,9 @@ int main(int argc, char **argv)
case L_POST_FILE:
post_file = optarg;
break;
+ case L_POST_TYPE:
+ post_type = optarg;
+ break;
case L_SPIDER:
no_output = true;
break;
--
2.28.0
More information about the openwrt-devel
mailing list