diff --git a/lib/core-net/connect.c b/lib/core-net/connect.c index 604bebb5c..3d01dc81a 100644 --- a/lib/core-net/connect.c +++ b/lib/core-net/connect.c @@ -141,7 +141,7 @@ lws_client_connect_via_info(const struct lws_client_connect_info *i) wsi->user_space = NULL; wsi->pending_timeout = NO_PENDING_TIMEOUT; wsi->position_in_fds_table = LWS_NO_FDS_POS; - wsi->c_port = i->port; + wsi->ocport = wsi->c_port = i->port; wsi->protocol = &wsi->vhost->protocols[0]; wsi->client_pipeline = !!(i->ssl_connection & LCCSCF_PIPELINE); diff --git a/lib/core-net/private.h b/lib/core-net/private.h index 015fbae01..326e6bae0 100644 --- a/lib/core-net/private.h +++ b/lib/core-net/private.h @@ -689,7 +689,7 @@ struct lws { #endif #ifndef LWS_NO_CLIENT - unsigned short c_port; + unsigned short ocport, c_port; #endif /* chars */ diff --git a/lib/roles/http/client/client-handshake.c b/lib/roles/http/client/client-handshake.c index cc13a8a18..b6552b271 100644 --- a/lib/roles/http/client/client-handshake.c +++ b/lib/roles/http/client/client-handshake.c @@ -422,10 +422,14 @@ create_new_conn: * Priority 1: connect to http proxy */ if (wsi->vhost->http.http_proxy_port) { + + lwsl_info("%s: going via proxy\n", __func__); + plen = lws_snprintf((char *)pt->serv_buf, 256, "CONNECT %s:%u HTTP/1.0\x0d\x0a" + "Host: %s:%u\x0d\x0a" "User-agent: libwebsockets\x0d\x0a", - ads, wsi->c_port); + ads, wsi->ocport, ads, wsi->ocport); if (wsi->vhost->proxy_basic_auth_token[0]) plen += lws_snprintf((char *)pt->serv_buf + plen, 256, diff --git a/lib/roles/http/client/client.c b/lib/roles/http/client/client.c index b1e795dc4..c168fa01e 100644 --- a/lib/roles/http/client/client.c +++ b/lib/roles/http/client/client.c @@ -291,14 +291,17 @@ socks_reply_fail: } pt->serv_buf[13] = '\0'; - if (strncmp(sb, "HTTP/1.0 200 ", 13) && - strncmp(sb, "HTTP/1.1 200 ", 13)) { + if (n < 13 || (strncmp(sb, "HTTP/1.0 200 ", 13) && + strncmp(sb, "HTTP/1.1 200 ", 13))) { lwsl_err("%s: ERROR proxy did not reply with h1\n", __func__); + /* lwsl_hexdump_notice(sb, n); */ cce = "proxy not h1"; goto bail3; } + lwsl_info("%s: proxy connection extablished\n", __func__); + /* clear his proxy connection timeout */ lws_set_timeout(wsi, NO_PENDING_TIMEOUT, 0);