aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2007-02-03 09:33:54 +0000
committerDaniel Stenberg <daniel@haxx.se>2007-02-03 09:33:54 +0000
commit138b4f27b46475e4d28ae8bb96ad9ae1395faabc (patch)
treebdcaf4b702712663aa9a8f0a304a8725aabd9a20
parentc26ec47e907e3707bdc94f116c0fcb2ba10fdb8c (diff)
- 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...
-rw-r--r--lib/url.c62
-rw-r--r--lib/urldata.h2
2 files changed, 34 insertions, 30 deletions
diff --git a/lib/url.c b/lib/url.c
index 916d2a63c..8b49033f3 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -2084,8 +2084,9 @@ ConnectionExists(struct SessionHandle *data,
}
}
else { /* The requested needle connection is using a proxy,
- is the checked one using the same? */
- if(check->bits.httpproxy &&
+ is the checked one using the same host, port and type? */
+ if(check->bits.proxy &&
+ (needle->proxytype == check->proxytype) &&
strequal(needle->proxy.name, check->proxy.name) &&
needle->port == check->port) {
/* This is the same proxy connection, use it! */
@@ -2240,10 +2241,10 @@ static CURLcode ConnectPlease(struct SessionHandle *data,
{
CURLcode result;
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",
- conn->bits.httpproxy?"proxy ":"",
+ conn->bits.proxy?"proxy ":"",
hostname, conn->port, conn->connectindex);
/*************************************************************
@@ -2287,7 +2288,7 @@ static CURLcode ConnectPlease(struct SessionHandle *data,
static void verboseconnect(struct connectdata *conn)
{
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);
}
@@ -2766,9 +2767,10 @@ static CURLcode CreateConnection(struct SessionHandle *data,
conn->sock[SECONDARYSOCKET] = CURL_SOCKET_BAD; /* no file descriptor */
conn->connectindex = -1; /* no index */
- conn->bits.httpproxy = (bool)(data->set.proxy /* http proxy or not */
- && *data->set.proxy
- && (data->set.proxytype == CURLPROXY_HTTP));
+ conn->proxytype = data->set.proxytype; /* type */
+ conn->bits.proxy = (bool)(data->set.proxy && *data->set.proxy);
+ conn->bits.httpproxy = (bool)(conn->bits.proxy
+ && (conn->proxytype == CURLPROXY_HTTP));
proxy = data->set.proxy; /* if global proxy is set, this is it */
/* Default protocol-independent behavior doesn't support persistent
@@ -2867,9 +2869,10 @@ static CURLcode CreateConnection(struct SessionHandle *data,
#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
* variables, to enable i.e Lynx compliance:
*
@@ -2964,11 +2967,14 @@ static CURLcode CreateConnection(struct SessionHandle *data,
if(proxy && *proxy) {
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 */
- conn->bits.httpproxy = TRUE;
+
+ if(conn->proxytype == CURLPROXY_HTTP) {
+ /* force this connection's protocol to become HTTP */
+ conn->protocol = PROT_HTTP | bits;
+ conn->bits.httpproxy = TRUE;
+ }
}
} /* if (!nope) - it wasn't specified non-proxy */
} /* NO_PROXY wasn't specified or '*' */
@@ -3081,7 +3087,7 @@ static CURLcode CreateConnection(struct SessionHandle *data,
conn->remote_port = (unsigned short)port;
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
switch and use HTTP operations only */
#ifndef CURL_DISABLE_HTTP
@@ -3686,17 +3692,16 @@ else {
}
/* host can change, when doing keepalive with a proxy ! */
- if (conn->bits.httpproxy) {
+ if (conn->bits.proxy) {
free(conn->host.rawalloc);
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 */
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 */
conn->bits.reuse = TRUE; /* yes, we're re-using here */
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",
conn->connectindex,
- conn->bits.httpproxy?conn->proxy.dispname:conn->host.dispname);
+ proxy?conn->proxy.dispname:conn->host.dispname);
}
else {
/*
@@ -3842,7 +3847,7 @@ else {
hostaddr = NULL;
/* 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);
}
else {
@@ -3961,17 +3966,14 @@ static CURLcode SetupConnection(struct connectdata *conn,
*protocol_done = FALSE; /* default to not done */
/*************************************************************
- * Send user-agent to HTTP proxies even if the target protocol
- * isn't HTTP.
+ * Set user-agent for HTTP
*************************************************************/
- if((conn->protocol&PROT_HTTP) || conn->bits.httpproxy) {
- if(data->set.useragent) {
- Curl_safefree(conn->allocptr.uagent);
- conn->allocptr.uagent =
- aprintf("User-Agent: %s\r\n", data->set.useragent);
- if(!conn->allocptr.uagent)
- return CURLE_OUT_OF_MEMORY;
- }
+ if((conn->protocol&PROT_HTTP) && data->set.useragent) {
+ Curl_safefree(conn->allocptr.uagent);
+ conn->allocptr.uagent =
+ aprintf("User-Agent: %s\r\n", data->set.useragent);
+ if(!conn->allocptr.uagent)
+ return CURLE_OUT_OF_MEMORY;
}
conn->headerbytecount = 0;
diff --git a/lib/urldata.h b/lib/urldata.h
index 9537ce36b..3bb3327ba 100644
--- a/lib/urldata.h
+++ b/lib/urldata.h
@@ -432,6 +432,7 @@ struct ConnectBits {
bool close; /* if set, we close the connection after this request */
bool reuse; /* if set, this is a re-used connection */
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 user_passwd; /* do we use user+password for this connection? */
bool proxy_user_passwd; /* user+password for the proxy? */
@@ -748,6 +749,7 @@ struct connectdata {
char *proxyuser; /* proxy user name 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 created; /* creation time */