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)