1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-22 08:08:50 -05:00

- Manfred Schwarb reported that socks5 support was broken and help us pinpoint

the problem. The code now tries harder to use httproxy and proxy where
  apppropriate, as not all proxies are HTTP...
This commit is contained in:
Daniel Stenberg 2007-02-03 09:33:54 +00:00
parent c26ec47e90
commit 138b4f27b4
2 changed files with 34 additions and 30 deletions

View File

@ -2084,8 +2084,9 @@ ConnectionExists(struct SessionHandle *data,
} }
} }
else { /* The requested needle connection is using a proxy, else { /* The requested needle connection is using a proxy,
is the checked one using the same? */ is the checked one using the same host, port and type? */
if(check->bits.httpproxy && if(check->bits.proxy &&
(needle->proxytype == check->proxytype) &&
strequal(needle->proxy.name, check->proxy.name) && strequal(needle->proxy.name, check->proxy.name) &&
needle->port == check->port) { needle->port == check->port) {
/* This is the same proxy connection, use it! */ /* This is the same proxy connection, use it! */
@ -2240,10 +2241,10 @@ static CURLcode ConnectPlease(struct SessionHandle *data,
{ {
CURLcode result; CURLcode result;
Curl_addrinfo *addr; Curl_addrinfo *addr;
char *hostname = conn->bits.httpproxy?conn->proxy.name:conn->host.name; char *hostname = conn->bits.proxy?conn->proxy.name:conn->host.name;
infof(data, "About to connect() to %s%s port %d (#%d)\n", infof(data, "About to connect() to %s%s port %d (#%d)\n",
conn->bits.httpproxy?"proxy ":"", conn->bits.proxy?"proxy ":"",
hostname, conn->port, conn->connectindex); hostname, conn->port, conn->connectindex);
/************************************************************* /*************************************************************
@ -2287,7 +2288,7 @@ static CURLcode ConnectPlease(struct SessionHandle *data,
static void verboseconnect(struct connectdata *conn) static void verboseconnect(struct connectdata *conn)
{ {
infof(conn->data, "Connected to %s (%s) port %d (#%d)\n", infof(conn->data, "Connected to %s (%s) port %d (#%d)\n",
conn->bits.httpproxy ? conn->proxy.dispname : conn->host.dispname, conn->bits.proxy ? conn->proxy.dispname : conn->host.dispname,
conn->ip_addr_str, conn->port, conn->connectindex); conn->ip_addr_str, conn->port, conn->connectindex);
} }
@ -2766,9 +2767,10 @@ static CURLcode CreateConnection(struct SessionHandle *data,
conn->sock[SECONDARYSOCKET] = CURL_SOCKET_BAD; /* no file descriptor */ conn->sock[SECONDARYSOCKET] = CURL_SOCKET_BAD; /* no file descriptor */
conn->connectindex = -1; /* no index */ conn->connectindex = -1; /* no index */
conn->bits.httpproxy = (bool)(data->set.proxy /* http proxy or not */ conn->proxytype = data->set.proxytype; /* type */
&& *data->set.proxy conn->bits.proxy = (bool)(data->set.proxy && *data->set.proxy);
&& (data->set.proxytype == CURLPROXY_HTTP)); conn->bits.httpproxy = (bool)(conn->bits.proxy
&& (conn->proxytype == CURLPROXY_HTTP));
proxy = data->set.proxy; /* if global proxy is set, this is it */ proxy = data->set.proxy; /* if global proxy is set, this is it */
/* Default protocol-independent behavior doesn't support persistent /* Default protocol-independent behavior doesn't support persistent
@ -2867,9 +2869,10 @@ static CURLcode CreateConnection(struct SessionHandle *data,
#ifndef CURL_DISABLE_HTTP #ifndef CURL_DISABLE_HTTP
/************************************************************* /*************************************************************
* Detect what (if any) proxy to use * Detect what (if any) proxy to use. Remember that this selects a host
* name and is not limited to HTTP proxies only.
*************************************************************/ *************************************************************/
if(!conn->bits.httpproxy) { if(!proxy) {
/* If proxy was not specified, we check for default proxy environment /* If proxy was not specified, we check for default proxy environment
* variables, to enable i.e Lynx compliance: * variables, to enable i.e Lynx compliance:
* *
@ -2964,12 +2967,15 @@ static CURLcode CreateConnection(struct SessionHandle *data,
if(proxy && *proxy) { if(proxy && *proxy) {
long bits = conn->protocol & (PROT_HTTPS|PROT_SSL|PROT_MISSING); long bits = conn->protocol & (PROT_HTTPS|PROT_SSL|PROT_MISSING);
/* force this to become HTTP */
conn->protocol = PROT_HTTP | bits;
proxy_alloc=TRUE; /* this needs to be freed later */ proxy_alloc=TRUE; /* this needs to be freed later */
if(conn->proxytype == CURLPROXY_HTTP) {
/* force this connection's protocol to become HTTP */
conn->protocol = PROT_HTTP | bits;
conn->bits.httpproxy = TRUE; conn->bits.httpproxy = TRUE;
} }
}
} /* if (!nope) - it wasn't specified non-proxy */ } /* if (!nope) - it wasn't specified non-proxy */
} /* NO_PROXY wasn't specified or '*' */ } /* NO_PROXY wasn't specified or '*' */
if(no_proxy) if(no_proxy)
@ -3081,7 +3087,7 @@ static CURLcode CreateConnection(struct SessionHandle *data,
conn->remote_port = (unsigned short)port; conn->remote_port = (unsigned short)port;
conn->protocol |= PROT_FTP; conn->protocol |= PROT_FTP;
if(proxy && *proxy && !data->set.tunnel_thru_httpproxy) { if(conn->bits.httpproxy && !data->set.tunnel_thru_httpproxy) {
/* Unless we have asked to tunnel ftp operations through the proxy, we /* Unless we have asked to tunnel ftp operations through the proxy, we
switch and use HTTP operations only */ switch and use HTTP operations only */
#ifndef CURL_DISABLE_HTTP #ifndef CURL_DISABLE_HTTP
@ -3686,17 +3692,16 @@ else {
} }
/* host can change, when doing keepalive with a proxy ! */ /* host can change, when doing keepalive with a proxy ! */
if (conn->bits.httpproxy) { if (conn->bits.proxy) {
free(conn->host.rawalloc); free(conn->host.rawalloc);
conn->host=old_conn->host; conn->host=old_conn->host;
} }
else
free(old_conn->host.rawalloc); /* free the newly allocated name buffer */
/* get the newly set value, not the old one */ /* get the newly set value, not the old one */
conn->bits.no_body = old_conn->bits.no_body; conn->bits.no_body = old_conn->bits.no_body;
if (!conn->bits.httpproxy)
free(old_conn->host.rawalloc); /* free the newly allocated name buffer */
/* re-use init */ /* re-use init */
conn->bits.reuse = TRUE; /* yes, we're re-using here */ conn->bits.reuse = TRUE; /* yes, we're re-using here */
conn->bits.chunk = FALSE; /* always assume not chunked unless told conn->bits.chunk = FALSE; /* always assume not chunked unless told
@ -3743,7 +3748,7 @@ else {
infof(data, "Re-using existing connection! (#%ld) with host %s\n", infof(data, "Re-using existing connection! (#%ld) with host %s\n",
conn->connectindex, conn->connectindex,
conn->bits.httpproxy?conn->proxy.dispname:conn->host.dispname); proxy?conn->proxy.dispname:conn->host.dispname);
} }
else { else {
/* /*
@ -3842,7 +3847,7 @@ else {
hostaddr = NULL; hostaddr = NULL;
/* we'll need to clear conn->dns_entry later in Curl_disconnect() */ /* we'll need to clear conn->dns_entry later in Curl_disconnect() */
if (conn->bits.httpproxy) if (conn->bits.proxy)
fix_hostname(data, conn, &conn->host); fix_hostname(data, conn, &conn->host);
} }
else { else {
@ -3961,18 +3966,15 @@ static CURLcode SetupConnection(struct connectdata *conn,
*protocol_done = FALSE; /* default to not done */ *protocol_done = FALSE; /* default to not done */
/************************************************************* /*************************************************************
* Send user-agent to HTTP proxies even if the target protocol * Set user-agent for HTTP
* isn't HTTP.
*************************************************************/ *************************************************************/
if((conn->protocol&PROT_HTTP) || conn->bits.httpproxy) { if((conn->protocol&PROT_HTTP) && data->set.useragent) {
if(data->set.useragent) {
Curl_safefree(conn->allocptr.uagent); Curl_safefree(conn->allocptr.uagent);
conn->allocptr.uagent = conn->allocptr.uagent =
aprintf("User-Agent: %s\r\n", data->set.useragent); aprintf("User-Agent: %s\r\n", data->set.useragent);
if(!conn->allocptr.uagent) if(!conn->allocptr.uagent)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
} }
}
conn->headerbytecount = 0; conn->headerbytecount = 0;

View File

@ -432,6 +432,7 @@ struct ConnectBits {
bool close; /* if set, we close the connection after this request */ bool close; /* if set, we close the connection after this request */
bool reuse; /* if set, this is a re-used connection */ bool reuse; /* if set, this is a re-used connection */
bool chunk; /* if set, this is a chunked transfer-encoding */ bool chunk; /* if set, this is a chunked transfer-encoding */
bool proxy; /* if set, this transfer is done through a proxy - any type */
bool httpproxy; /* if set, this transfer is done through a http proxy */ bool httpproxy; /* if set, this transfer is done through a http proxy */
bool user_passwd; /* do we use user+password for this connection? */ bool user_passwd; /* do we use user+password for this connection? */
bool proxy_user_passwd; /* user+password for the proxy? */ bool proxy_user_passwd; /* user+password for the proxy? */
@ -748,6 +749,7 @@ struct connectdata {
char *proxyuser; /* proxy user name string, allocated */ char *proxyuser; /* proxy user name string, allocated */
char *proxypasswd; /* proxy password string, allocated */ char *proxypasswd; /* proxy password string, allocated */
curl_proxytype proxytype; /* what kind of proxy that is in use */
struct timeval now; /* "current" time */ struct timeval now; /* "current" time */
struct timeval created; /* creation time */ struct timeval created; /* creation time */