URLConnection with FTP protocol

Ito Kazumitsu ito.kazumitsu at hitachi-cable.co.jp
Thu Apr 26 21:47:32 PDT 2001


In message "Re: URLConnection with FTP protocol"
    on 01/04/26, Ito Kazumitsu <ito.kazumitsu at hitachi-cable.co.jp> writes:

> One thing I am worried about is that proxyHost, useProxy
> and proxyPort are static.  Changing their values may
> cause some trouble.

So this should be safer.

--- HttpURLConnection.java.orig	Fri Jun 16 16:23:15 2000
+++ HttpURLConnection.java	Fri Apr 27 13:33:08 2001
@@ -27,9 +27,12 @@
 public class HttpURLConnection
   extends java.net.HttpURLConnection {
 
-private static String proxyHost;
-private static int proxyPort = -1;
-private static boolean useProxy = false;
+private static String defaultProxyHost;
+private static int defaultProxyPort = -1;
+private static boolean defaultUseProxy = false;
+private String proxyHost;
+private int proxyPort;
+private boolean useProxy;
 
 // store header fields as (key, value) pairs
 private Vector headerFields = new Vector(0);
@@ -42,8 +45,8 @@
 static {
 	// How these properties are undocumented in the API doc.  We know
 	// about them from www.icesoft.no's webpage
-	proxyHost = System.getProperty("http.proxyHost");
-	if (proxyHost != null) {
+	defaultProxyHost = System.getProperty("http.proxyHost");
+	if (defaultProxyHost != null) {
 		// Sun also supports a http.nonProxyHosts property to
 		// avoid proxy use for local sites.  It's a regular expression
 		// like so "*.pa.dec.com|*.compaq.com"
@@ -52,10 +55,10 @@
 		// In JDK 1.2, the properties are read when an connection
 		// is established, allowing the use of different proxies
 		// during the run-time of a program.  FIXME
-		useProxy = true;
+		defaultUseProxy = true;
 		String pp = System.getProperty("http.proxyPort");
 		if (pp != null) {
-			proxyPort = Integer.parseInt(pp);
+			defaultProxyPort = Integer.parseInt(pp);
 		}
 	}
 }
@@ -63,6 +66,20 @@
 
 public HttpURLConnection(URL url) {
 	super(url);
+	proxyHost = defaultProxyHost;
+	useProxy = defaultUseProxy;
+	proxyPort = defaultProxyPort;
+	if ((url.getProtocol()).equals("ftp")) {
+		proxyHost = System.getProperty("ftp.proxyHost");
+		if (proxyHost != null) {
+			useProxy = true;
+			String pp = System.getProperty("ftp.proxyPort");
+			if (pp != null) {
+				proxyPort = Integer.parseInt(pp);
+			}
+		}
+		// else I do not care.
+	}
 }
 
 public void connect() throws IOException {


More information about the kaffe mailing list