Skip to content
Snippets Groups Projects
Commit 36efd82d authored by Andy Green's avatar Andy Green
Browse files

defer changing to proxy uri until connected


Reported-by: shyswork
Signed-off-by: default avatarAndy Green <andy.green@linaro.org>
parent 68114573
Branches
Tags
No related merge requests found
......@@ -25,25 +25,16 @@ struct libwebsocket *__libwebsocket_client_connect_2(
"\x0d\x0a",
lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_PEER_ADDRESS),
wsi->u.hdr.ah->c_port);
/* OK from now on we talk via the proxy, so connect to that */
/*
* (will overwrite existing pointer,
* leaving old string/frag there but unreferenced)
*/
if (lws_hdr_simple_create(wsi, _WSI_TOKEN_CLIENT_PEER_ADDRESS,
context->http_proxy_address))
goto oom4;
wsi->u.hdr.ah->c_port = context->http_proxy_port;
ads = context->http_proxy_address;
server_addr.sin_port = htons(context->http_proxy_port);
} else {
ads = lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_PEER_ADDRESS);
server_addr.sin_port = htons(wsi->u.hdr.ah->c_port);
}
/*
* prepare the actual connection (to the proxy, if any)
*/
ads = lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_PEER_ADDRESS);
lwsl_client("__libwebsocket_client_connect_2: address %s\n", ads);
server_hostent = gethostbyname(ads);
......@@ -77,8 +68,8 @@ struct libwebsocket *__libwebsocket_client_connect_2(
}
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(wsi->u.hdr.ah->c_port);
server_addr.sin_addr = *((struct in_addr *)server_hostent->h_addr);
bzero(&server_addr.sin_zero, 8);
if (connect(wsi->sock, (struct sockaddr *)&server_addr,
......@@ -112,6 +103,17 @@ struct libwebsocket *__libwebsocket_client_connect_2(
if (context->http_proxy_port) {
/* OK from now on we talk via the proxy, so connect to that */
/*
* (will overwrite existing pointer,
* leaving old string/frag there but unreferenced)
*/
if (lws_hdr_simple_create(wsi, _WSI_TOKEN_CLIENT_PEER_ADDRESS,
context->http_proxy_address))
goto failed;
wsi->u.hdr.ah->c_port = context->http_proxy_port;
n = send(wsi->sock, context->service_buffer, plen, MSG_NOSIGNAL);
if (n < 0) {
lwsl_debug("ERROR writing to proxy socket\n");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment