From patchwork Thu Jun 3 05:57:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Heider X-Patchwork-Id: 1486984 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=1jTn58ry; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=J1bBar4Q; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FwZyZ37wJz9s5R for ; Thu, 3 Jun 2021 16:01:09 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To :From:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=l1HZCTPH0uJCpADe264NFveLONQK/fD5Kg++aBNy4Rg=; b=1jTn58ryDRpIQ4 qZtWi792Hi7E3kJ0N58nz66OVhKZE/txcr68rvRV9hpxmGVRua78N0M+tBCoo3P485sCx06Gq4rgP jEcnexjV88aA53xTHr4t+BRxk5fXXHTifqQuYXCwCCsbWSrd9z0lGffDUjlExGDeZkTSVPzQUGVQr DLvAafUp8lCBafdneHHkgYDsjhZn3xnxKiODjrHd2cJmQols63SS0gsMqL7c+6TSGZvlx6dsaX4qf A2oNcmj4J9Sg59eHosNcFwfPsbF73ETj2p9wMQwWXOXKLSakU+nSm3H0jZxTbu2LQuoRDwelwwKS6 IripnVcT29S0nyFQlJWA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1logNa-007F2N-Dw; Thu, 03 Jun 2021 05:58:54 +0000 Received: from mail-wr1-f44.google.com ([209.85.221.44]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1logNU-007F1W-L7 for openwrt-devel@lists.openwrt.org; Thu, 03 Jun 2021 05:58:52 +0000 Received: by mail-wr1-f44.google.com with SMTP id f2so4506380wri.11 for ; Wed, 02 Jun 2021 22:58:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=tJ7Nuc8vbjoLbLKMsc/spgucYhaZcbIE+IVnL+G2jwQ=; b=J1bBar4QqtsHj1IUEVHIf/HD9Hje71aO6zFKaVmyTaFTJ9ZbzVdJg4v8PaidClW3qp iLRAkeTcQcR7ppcBfn1LLSllEkCZkY1C1ImtOOb433z+XRCdQ4/FyW++V3cUyRR8XPtu 8GsHbP2tq3gnYWWWdK7LnycOnBRIMxFy2GwEM6ds7XdhHk4XPPodRtVgisksNIJlQ6JL sJZyP8JMXaCcg2Hncsb4TudiRgd9l3boOVKplvIRvrw3tOPXt5h4f1HzkyaBiB3lVOi5 CygQ9WuJ/bOSl1EfFllNkYPAXAtEoWbFTZ8y0SlPVvpiempsU4BW1B+Jnk/N3ze2m+Tj YmMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=tJ7Nuc8vbjoLbLKMsc/spgucYhaZcbIE+IVnL+G2jwQ=; b=CI5JCTCzY5r/Xaip+OHZ5MtEyvcX3UpmlipOgU4mGxfCEIDhoGR40GF1ehtZgcInqW 6GwprNfDMoALsUxkHl/FYy+LCuZGnhOVFK21tivHErHm2MiEaiP6geDmQBF7HLQNjL0y GofPpet3eb87vwUd9lgx2M52Tkq9Cf8w6/zTdC5w9QaWgoiaxx+Z+KqllNwGhJ7zJiX5 01U4LlFyfxB1bneX5OLzc0aB+dA1wGimkpcL2Oz0yn8NZ/3In/u5K4N7xHIbMutE15AG 3x8T75EgjehjfAUcH1usutjmAnxx/RmfD9WKRLVKiW2UGSDwv/SwwXeRwF67WpxRmyI3 3xGQ== X-Gm-Message-State: AOAM530k2vbwDON5QkHMXibZonKe1ElQErCe4K00xHGTGqpxQdO4pu65 JdEYvu6Y18PeGREmpjIxZNuvxPmRKFc= X-Google-Smtp-Source: ABdhPJyDrKwIPbyzYfvN9p6m4symsw3htsQvrfyX3N5EIPI+Imx2PsuXG0JmLCtk6ir/7RT70HYaIg== X-Received: by 2002:adf:f7d1:: with SMTP id a17mr18727340wrq.84.1622699865679; Wed, 02 Jun 2021 22:57:45 -0700 (PDT) Received: from mamamia.internal (a89-182-186-88.net-htp.de. [89.182.186.88]) by smtp.gmail.com with ESMTPSA id c15sm2107933wrd.49.2021.06.02.22.57.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jun 2021 22:57:45 -0700 (PDT) From: Andre Heider To: openwrt-devel@lists.openwrt.org Subject: [PATCH uclient] uclient-fetch: allow to overwrite Content-Type header for POST Date: Thu, 3 Jun 2021 07:57:44 +0200 Message-Id: <20210603055744.222990-1-a.heider@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210602_225848_717214_602DF5D0 X-CRM114-Status: GOOD ( 10.75 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: This is required by some APIs, e.g. matrix's media upload [0]. [0] https://matrix.org/docs/spec/client_server/latest#post-matrix-media-r0-upload Signed-off-by: Andre Heider --- uclient-fetch.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [209.85.221.44 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.221.44 listed in wl.mailspike.net] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [a.heider[at]gmail.com] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org This is required by some APIs, e.g. matrix's media upload [0]. [0] https://matrix.org/docs/spec/client_server/latest#post-matrix-media-r0-upload Signed-off-by: Andre Heider --- uclient-fetch.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/uclient-fetch.c b/uclient-fetch.c index 282092e..176fd37 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 *content_type = "application/x-www-form-urlencoded"; static struct ustream_ssl_ctx *ssl_ctx; static const struct ustream_ssl_ops *ssl_ops; static int quiet = false; @@ -346,13 +347,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", content_type); 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", content_type); input_file = fopen(post_file, "r"); if (!input_file) @@ -484,6 +485,7 @@ static int usage(const char *progname) " --user-agent | -U 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" + " --content-type=STRING use STRING as Content-Type for the 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 | -Y on Enable interpretation of proxy env vars (default)\n" @@ -544,6 +546,7 @@ enum { L_USER_AGENT, L_POST_DATA, L_POST_FILE, + L_CONTENT_TYPE, L_SPIDER, L_TIMEOUT, L_CONTINUE, @@ -561,6 +564,7 @@ static const struct option longopts[] = { [L_USER_AGENT] = { "user-agent", required_argument, NULL, 0 }, [L_POST_DATA] = { "post-data", required_argument, NULL, 0 }, [L_POST_FILE] = { "post-file", required_argument, NULL, 0 }, + [L_CONTENT_TYPE] = { "content-type", required_argument, NULL, 0 }, [L_SPIDER] = { "spider", no_argument, NULL, 0 }, [L_TIMEOUT] = { "timeout", required_argument, NULL, 0 }, [L_CONTINUE] = { "continue", no_argument, NULL, 0 }, @@ -632,6 +636,9 @@ int main(int argc, char **argv) case L_POST_FILE: post_file = optarg; break; + case L_CONTENT_TYPE: + content_type = optarg; + break; case L_SPIDER: no_output = true; break;