diff --git a/src/MQTTAsync.h b/src/MQTTAsync.h index 3d597ce0..3c8daa88 100644 --- a/src/MQTTAsync.h +++ b/src/MQTTAsync.h @@ -78,6 +78,7 @@ *
  • @ref tracing
  • *
  • @ref auto_reconnect
  • *
  • @ref offline_publish
  • + *
  • @ref HTTP_proxies
  • * * @endcond */ @@ -1374,11 +1375,13 @@ typedef struct */ const MQTTAsync_nameValue* httpHeaders; /** - * HTTP proxy - */ + * The string value of the HTTP proxy. Examples: + * - http://your.proxy.server:8080/ + * - http://user:pass@my.proxy.server:8080/ + */ const char* httpProxy; /** - * HTTPS proxy + * HTTPS proxy setting. See ::MQTTAsync_connectOptions.httpProxy and the section @ref HTTP_proxies. */ const char* httpsProxy; } MQTTAsync_connectOptions; @@ -2377,6 +2380,17 @@ exit: 20130528 163909.209 Heap scan end * @endcode * @endcond + * +√* @page HTTP_proxies HTTP Proxies + * The use of HTTP proxies can be controlled by environment variables or API calls. + * + * The ::MQTTAsync_connectOptions.httpProxy and ::MQTTAsync_connectOptions.httpsProxy fields + * of the ::MQTTAsync_connectOptions structure override any settings in the environment. + * + * If the environment variable PAHO_C_CLIENT_USE_HTTP_PROXY is set to TRUE, then the + * http_proxy or https_proxy environment variables are used, for plain TCP and TLS-secured + * connections respectively. + * */ #if defined(__cplusplus) diff --git a/src/MQTTClient.h b/src/MQTTClient.h index 38aa1836..779fd9a2 100644 --- a/src/MQTTClient.h +++ b/src/MQTTClient.h @@ -97,6 +97,7 @@ *
  • @ref wildcard
  • *
  • @ref qos
  • *
  • @ref tracing
  • + *
  • @ref HTTP_proxies
  • * * @endcond */ @@ -971,12 +972,14 @@ typedef struct */ const MQTTClient_nameValue* httpHeaders; /** - * HTTP proxy - */ + * The string value of the HTTP proxy. Examples: + * - http://your.proxy.server:8080/ + * - http://user:pass@my.proxy.server:8080/ + */ const char* httpProxy; /** - * HTTPS proxy - */ + * HTTPS proxy setting. See ::MQTTClient_connectOptions.httpProxy and the section @ref HTTP_proxies. + */ const char* httpsProxy; } MQTTClient_connectOptions; @@ -1979,4 +1982,15 @@ exit: 20130528 163909.209 Heap scan end * @endcode * @endcond + * +* √* @page HTTP_proxies HTTP Proxies + * The use of HTTP proxies can be controlled by environment variables or API calls. + * + * The ::MQTTClient_connectOptions.httpProxy and ::MQTTClient_connectOptions.httpsProxy fields + * of the ::MQTTClient_connectOptions structure override any settings in the environment. + * + * If the environment variable PAHO_C_CLIENT_USE_HTTP_PROXY is set to TRUE, then the + * http_proxy or https_proxy environment variables are used, for plain TCP and TLS-secured + * connections respectively. + * */ diff --git a/src/MQTTProtocolOut.c b/src/MQTTProtocolOut.c index a7ad694f..1028737f 100644 --- a/src/MQTTProtocolOut.c +++ b/src/MQTTProtocolOut.c @@ -222,7 +222,7 @@ int MQTTProtocol_connect(const char* ip_address, Clients* aClient, int websocket int rc = 0, port; size_t addr_len; - char* p0; + char* p0 = NULL; FUNC_ENTRY; aClient->good = 1; @@ -230,7 +230,15 @@ int MQTTProtocol_connect(const char* ip_address, Clients* aClient, int websocket if (aClient->httpProxy) p0 = aClient->httpProxy; else - p0 = getenv("http_proxy"); + { + /* Don't use the environment HTTP proxy settings by default - for backwards compatibility */ + char* use_proxy = getenv("PAHO_C_CLIENT_USE_HTTP_PROXY"); + if (use_proxy) + { + if (strncmp(use_proxy, "TRUE", strlen("TRUE")) == 0) + p0 = getenv("http_proxy"); + } + } if (p0) {