mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
http_proxy: fixes
Eg, http_proxy=http://127.0.0.1:3128 ./bin/lws-minimal-http-client works OK on h1 + h2
This commit is contained in:
parent
6975847e62
commit
44585d0fc0
4 changed files with 31 additions and 21 deletions
|
@ -142,7 +142,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);
|
||||
|
|
|
@ -757,7 +757,7 @@ struct lws {
|
|||
unsigned int sock_send_blocking:1;
|
||||
#endif
|
||||
|
||||
uint16_t c_port;
|
||||
uint16_t ocport, c_port;
|
||||
uint16_t retry;
|
||||
|
||||
/* chars */
|
||||
|
|
|
@ -81,6 +81,30 @@ lws_client_connect_4_established(struct lws *wsi, struct lws *wsi_piggyback,
|
|||
|
||||
/* http proxy */
|
||||
if (wsi->vhost->http.http_proxy_port) {
|
||||
const char *cpa;
|
||||
|
||||
if (wsi->stash)
|
||||
cpa = wsi->stash->cis[CIS_ADDRESS];
|
||||
else
|
||||
cpa = lws_hdr_simple_ptr(wsi,
|
||||
_WSI_TOKEN_CLIENT_PEER_ADDRESS);
|
||||
|
||||
lwsl_info("%s: going via proxy\n", __func__);
|
||||
|
||||
plen = lws_snprintf((char *)pt->serv_buf, 256,
|
||||
"CONNECT %s:%u HTTP/1.1\x0d\x0a"
|
||||
"Host: %s:%u\x0d\x0a"
|
||||
"User-agent: lws\x0d\x0a", cpa, wsi->ocport,
|
||||
cpa, wsi->ocport);
|
||||
|
||||
if (wsi->vhost->proxy_basic_auth_token[0])
|
||||
plen += lws_snprintf((char *)pt->serv_buf + plen, 256,
|
||||
"Proxy-authorization: basic %s\x0d\x0a",
|
||||
wsi->vhost->proxy_basic_auth_token);
|
||||
|
||||
plen += lws_snprintf((char *)pt->serv_buf + plen, 5, "\x0d\x0a");
|
||||
|
||||
/* lwsl_hexdump_notice(pt->serv_buf, plen); */
|
||||
|
||||
/*
|
||||
* OK from now on we talk via the proxy, so connect to that
|
||||
|
@ -241,12 +265,6 @@ lws_client_connect_3_connect(struct lws *wsi, const char *ads,
|
|||
#if defined(LWS_WITH_UNIX_SOCK)
|
||||
struct sockaddr_un sau;
|
||||
#endif
|
||||
#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
|
||||
#endif
|
||||
#ifdef LWS_WITH_IPV6
|
||||
char ipv6only = lws_check_opt(wsi->vhost->options,
|
||||
LWS_SERVER_OPTION_IPV6_V6ONLY_MODIFY |
|
||||
|
@ -363,17 +381,6 @@ lws_client_connect_3_connect(struct lws *wsi, const char *ads,
|
|||
* Priority 1: connect to http proxy */
|
||||
|
||||
if (wsi->vhost->http.http_proxy_port) {
|
||||
plen = lws_snprintf((char *)pt->serv_buf, 256,
|
||||
"CONNECT %s:%u HTTP/1.0\x0d\x0a"
|
||||
"User-agent: libwebsockets\x0d\x0a",
|
||||
ads, wsi->c_port);
|
||||
|
||||
if (wsi->vhost->proxy_basic_auth_token[0])
|
||||
plen += lws_snprintf((char *)pt->serv_buf + plen, 256,
|
||||
"Proxy-authorization: basic %s\x0d\x0a",
|
||||
wsi->vhost->proxy_basic_auth_token);
|
||||
|
||||
plen += lws_snprintf((char *)pt->serv_buf + plen, 5, "\x0d\x0a");
|
||||
ads = wsi->vhost->http.http_proxy_address;
|
||||
wsi->c_port = wsi->vhost->http.http_proxy_port;
|
||||
#else
|
||||
|
|
|
@ -302,14 +302,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);
|
||||
|
|
Loading…
Add table
Reference in a new issue