1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-16 00:00:07 +01:00

Allow setting the HTTP proxy via creation info

If the user provides a proxy via the info object it is used
in favor over the http_proxy environment variable.
This commit is contained in:
Patrick Gansterer 2014-02-28 02:31:23 +01:00
parent 02684c54fb
commit 7c7bc10bbc
2 changed files with 21 additions and 9 deletions

View file

@ -2090,21 +2090,31 @@ libwebsocket_create_context(struct lws_context_creation_info *info)
/* split the proxy ads:port if given */
p = getenv("http_proxy");
if (p) {
strncpy(context->http_proxy_address, p,
if (info->http_proxy_address) {
strncpy(context->http_proxy_address, info->http_proxy_address,
sizeof(context->http_proxy_address) - 1);
context->http_proxy_address[
sizeof(context->http_proxy_address) - 1] = '\0';
context->http_proxy_port = info->http_proxy_port;
} else {
p = getenv("http_proxy");
if (p) {
strncpy(context->http_proxy_address, p,
sizeof(context->http_proxy_address) - 1);
context->http_proxy_address[
sizeof(context->http_proxy_address) - 1] = '\0';
p = strchr(context->http_proxy_address, ':');
if (p == NULL) {
lwsl_err("http_proxy needs to be ads:port\n");
goto bail;
p = strchr(context->http_proxy_address, ':');
if (p == NULL) {
lwsl_err("http_proxy needs to be ads:port\n");
goto bail;
}
*p = '\0';
context->http_proxy_port = atoi(p + 1);
}
*p = '\0';
context->http_proxy_port = atoi(p + 1);
}
if (context->http_proxy_address[0]) {
lwsl_notice(" Proxy %s:%u\n",
context->http_proxy_address,
context->http_proxy_port);

View file

@ -938,6 +938,8 @@ struct lws_context_creation_info {
const char *ssl_private_key_filepath;
const char *ssl_ca_filepath;
const char *ssl_cipher_list;
const char *http_proxy_address;
unsigned int http_proxy_port;
int gid;
int uid;
unsigned int options;