You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/06/15 12:40:58 UTC
[incubator-nuttx-apps] branch master updated: webclient: Allow users to specify extra headers for proxy
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new 159ca0075 webclient: Allow users to specify extra headers for proxy
159ca0075 is described below
commit 159ca0075231c0790b7680ef99b6680fd9ad1e37
Author: YAMAMOTO Takashi <ya...@midokura.com>
AuthorDate: Mon Jun 6 16:00:37 2022 +0900
webclient: Allow users to specify extra headers for proxy
My primary motivation at this point is to use it for basic proxy auth.
(specify "Proxy-Authorization" header)
But there can be other use cases for proxy-specific extra headers.
If/when we want to support other non-trivial auth methods, probably
a callback-based mechanism will be necessary. But at this point,
this serves my purpose well.
---
include/netutils/webclient.h | 8 ++++++++
netutils/webclient/webclient.c | 33 ++++++++++++++++++++++++++++++---
2 files changed, 38 insertions(+), 3 deletions(-)
diff --git a/include/netutils/webclient.h b/include/netutils/webclient.h
index c17027499..2667eef90 100644
--- a/include/netutils/webclient.h
+++ b/include/netutils/webclient.h
@@ -360,6 +360,10 @@ struct webclient_context
* unix_socket_path - If not NULL, the path to an AF_LOCAL socket.
* headers - An array of pointers to the extra headers.
* nheaders - The number of elements in the "headers" array.
+ * proxy_headers - An array of pointers to the extra headers for
+ * the proxy connection.
+ * proxy_nheaders - The number of elements in the "headers" array for
+ * the proxy connection.
* bodylen - The size of the request body.
* timeout_sec - The timeout in second.
* This is not meant to cover the entire transaction.
@@ -384,6 +388,10 @@ struct webclient_context
#endif
FAR const char * FAR const *headers;
unsigned int nheaders;
+
+ FAR const char * FAR const *proxy_headers;
+ unsigned int proxy_nheaders;
+
size_t bodylen;
unsigned int timeout_sec;
diff --git a/netutils/webclient/webclient.c b/netutils/webclient/webclient.c
index 4dc673021..6cbbc742a 100644
--- a/netutils/webclient/webclient.c
+++ b/netutils/webclient/webclient.c
@@ -1337,6 +1337,8 @@ int webclient_perform(FAR struct webclient_context *ctx)
tunnel->tunnel_target_host = ws->target.hostname;
tunnel->tunnel_target_port = ws->target.port;
tunnel->proxy = ctx->proxy;
+ tunnel->proxy_headers = ctx->proxy_headers;
+ tunnel->proxy_nheaders = ctx->proxy_nheaders;
/* Inherit some configurations.
*
@@ -1700,10 +1702,35 @@ int webclient_perform(FAR struct webclient_context *ctx)
dest = append(dest, ep, ws->target.hostname);
dest = append(dest, ep, g_httpcrnl);
- for (i = 0; i < ctx->nheaders; i++)
+ /* Append user-specified headers.
+ *
+ * - For non-proxied request,
+ * only send "headers".
+ *
+ * - For proxied request, (traditional http proxy)
+ * send both of "headers" and "proxy_headers".
+ *
+ * - For tunneling request, (WEBCLIENT_FLAG_TUNNEL)
+ * only send "proxy_headers".
+ */
+
+ if ((ctx->flags & WEBCLIENT_FLAG_TUNNEL) == 0)
{
- dest = append(dest, ep, ctx->headers[i]);
- dest = append(dest, ep, g_httpcrnl);
+ for (i = 0; i < ctx->nheaders; i++)
+ {
+ dest = append(dest, ep, ctx->headers[i]);
+ dest = append(dest, ep, g_httpcrnl);
+ }
+ }
+
+ if ((ctx->flags & WEBCLIENT_FLAG_TUNNEL) != 0 ||
+ ctx->proxy != NULL)
+ {
+ for (i = 0; i < ctx->proxy_nheaders; i++)
+ {
+ dest = append(dest, ep, ctx->proxy_headers[i]);
+ dest = append(dest, ep, g_httpcrnl);
+ }
}
if (ctx->bodylen)