mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
client: make external http proxying optional
Add LWS_CLIENT_HTTP_PROXYING on by default. Removing it saves a few hundred bytes of code and 128 bytes per vhost in heap.
This commit is contained in:
parent
c099e7be92
commit
f8afcd0e5c
6 changed files with 24 additions and 9 deletions
|
@ -33,7 +33,7 @@ option(LWS_WITH_CGI "Include CGI (spawn process with network-connected stdin/out
|
|||
option(LWS_IPV6 "Compile with support for ipv6" OFF)
|
||||
option(LWS_UNIX_SOCK "Compile with support for UNIX domain socket" OFF)
|
||||
option(LWS_WITH_PLUGINS "Support plugins for protocols and extensions" OFF)
|
||||
option(LWS_WITH_HTTP_PROXY "Support for HTTP proxying" OFF)
|
||||
option(LWS_WITH_HTTP_PROXY "Support for active HTTP proxying" OFF)
|
||||
option(LWS_WITH_ZIP_FOPS "Support serving pre-zipped files" OFF)
|
||||
option(LWS_WITH_SOCKS5 "Allow use of SOCKS5 proxy on client connections" OFF)
|
||||
option(LWS_WITH_GENERIC_SESSIONS "With the Generic Sessions plugin" OFF)
|
||||
|
@ -133,6 +133,7 @@ option(LWS_WITH_DEPRECATED_LWS_DLL "Migrate to lws_dll2 instead ASAP" OFF)
|
|||
option(LWS_WITH_SEQUENCER "lws_seq_t support" ON)
|
||||
option(LWS_WITH_EXTERNAL_POLL "Support external POLL integration using callback messages (not recommended)" OFF)
|
||||
option(LWS_WITH_LWS_DSH "Support lws_dsh_t Disordered Shared Heap" OFF)
|
||||
option(LWS_CLIENT_HTTP_PROXYING "Support external http proxies for client connections" ON)
|
||||
#
|
||||
# to use miniz, enable both LWS_WITH_ZLIB and LWS_WITH_MINIZ
|
||||
#
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#cmakedefine LWS_AVOID_SIGPIPE_IGN
|
||||
#cmakedefine LWS_BUILD_HASH "${LWS_BUILD_HASH}"
|
||||
#cmakedefine LWS_BUILTIN_GETIFADDRS
|
||||
#cmakedefine LWS_CLIENT_HTTP_PROXYING
|
||||
#cmakedefine LWS_FALLBACK_GETHOSTBYNAME
|
||||
#cmakedefine LWS_HAS_INTPTR_T
|
||||
#cmakedefine LWS_HAS_GETOPT_LONG
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
|
||||
#include "private-lib-core.h"
|
||||
|
||||
#if defined(LWS_CLIENT_HTTP_PROXYING)
|
||||
|
||||
LWS_VISIBLE int
|
||||
lws_set_proxy(struct lws_vhost *vhost, const char *proxy)
|
||||
{
|
||||
|
@ -116,4 +118,4 @@ auth_too_long:
|
|||
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -440,7 +440,8 @@ lws_create_vhost(struct lws_context *context,
|
|||
struct lws_protocols *lwsp;
|
||||
int m, f = !info->pvo, fx = 0, abs_pcol_count = 0;
|
||||
char buf[96];
|
||||
#if !defined(LWS_WITHOUT_CLIENT) && defined(LWS_HAVE_GETENV)
|
||||
#if defined(LWS_CLIENT_HTTP_PROXYING) && \
|
||||
!defined(LWS_WITHOUT_CLIENT) && defined(LWS_HAVE_GETENV)
|
||||
char *p;
|
||||
#endif
|
||||
int n;
|
||||
|
@ -674,18 +675,17 @@ lws_create_vhost(struct lws_context *context,
|
|||
}
|
||||
|
||||
vh->listen_port = info->port;
|
||||
#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)
|
||||
vh->http.http_proxy_port = 0;
|
||||
vh->http.http_proxy_address[0] = '\0';
|
||||
#endif
|
||||
|
||||
#if defined(LWS_WITH_SOCKS5)
|
||||
vh->socks_proxy_port = 0;
|
||||
vh->socks_proxy_address[0] = '\0';
|
||||
#endif
|
||||
|
||||
#if !defined(LWS_WITHOUT_CLIENT)
|
||||
#if !defined(LWS_WITHOUT_CLIENT) && defined(LWS_CLIENT_HTTP_PROXYING)
|
||||
/* either use proxy from info, or try get it from env var */
|
||||
#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)
|
||||
vh->http.http_proxy_port = 0;
|
||||
vh->http.http_proxy_address[0] = '\0';
|
||||
/* http proxy */
|
||||
if (info->http_proxy_address) {
|
||||
/* override for backwards compatibility */
|
||||
|
|
|
@ -53,7 +53,9 @@ lws_getaddrinfo46(struct lws *wsi, const char *ads, struct addrinfo **result)
|
|||
struct lws *
|
||||
lws_client_connect_3(struct lws *wsi, struct lws *wsi_piggyback, ssize_t plen)
|
||||
{
|
||||
#if defined(LWS_CLIENT_HTTP_PROXYING)
|
||||
struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi];
|
||||
#endif
|
||||
const char *meth = NULL;
|
||||
struct lws_pollfd pfd;
|
||||
const char *cce = "";
|
||||
|
@ -70,6 +72,7 @@ lws_client_connect_3(struct lws *wsi, struct lws *wsi_piggyback, ssize_t plen)
|
|||
if (wsi_piggyback)
|
||||
goto send_hs;
|
||||
|
||||
#if defined(LWS_CLIENT_HTTP_PROXYING)
|
||||
#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)
|
||||
/* we are connected to server, or proxy */
|
||||
|
||||
|
@ -105,6 +108,7 @@ lws_client_connect_3(struct lws *wsi, struct lws *wsi_piggyback, ssize_t plen)
|
|||
return wsi;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#if defined(LWS_WITH_SOCKS5)
|
||||
/* socks proxy */
|
||||
else if (wsi->vhost->socks_proxy_port) {
|
||||
|
@ -227,8 +231,10 @@ struct lws *
|
|||
lws_client_connect_2(struct lws *wsi)
|
||||
{
|
||||
#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)
|
||||
#if defined(LWS_CLIENT_HTTP_PROXYING)
|
||||
struct lws_context *context = wsi->context;
|
||||
struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi];
|
||||
#endif
|
||||
const char *adsin;
|
||||
ssize_t plen = 0;
|
||||
#endif
|
||||
|
@ -434,7 +440,8 @@ create_new_conn:
|
|||
}
|
||||
#endif
|
||||
|
||||
#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)
|
||||
#if defined(LWS_CLIENT_HTTP_PROXYING) && \
|
||||
(defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2))
|
||||
|
||||
/* Decide what it is we need to connect to:
|
||||
*
|
||||
|
|
|
@ -191,10 +191,14 @@ struct lws_peer_role_http {
|
|||
};
|
||||
|
||||
struct lws_vhost_role_http {
|
||||
#if defined(LWS_CLIENT_HTTP_PROXYING)
|
||||
char http_proxy_address[128];
|
||||
#endif
|
||||
const struct lws_http_mount *mount_list;
|
||||
const char *error_document_404;
|
||||
#if defined(LWS_CLIENT_HTTP_PROXYING)
|
||||
unsigned int http_proxy_port;
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef LWS_WITH_ACCESS_LOG
|
||||
|
|
Loading…
Add table
Reference in a new issue