Connection.java (proxyPort, [...]): New static fields.

2003-01-03  Joerg Brunsmann  <joerg_brunsmann@yahoo.de>

	* gnu/gcj/protocol/http/Connection.java (proxyPort, proxyInUse,
	proxyHost): New static fields.
	(<clinit>): Initialize new fields.
	(connect): Use proxy if necessary.
	(usingProxy): Implement.

From-SVN: r60846
This commit is contained in:
Joerg Brunsmann 2003-01-03 18:05:00 +00:00 committed by Tom Tromey
parent 0320cac3d8
commit 9c91c80bb7
2 changed files with 55 additions and 12 deletions

View File

@ -1,3 +1,11 @@
2003-01-03 Joerg Brunsmann <joerg_brunsmann@yahoo.de>
* gnu/gcj/protocol/http/Connection.java (proxyPort, proxyInUse,
proxyHost): New static fields.
(<clinit>): Initialize new fields.
(connect): Use proxy if necessary.
(usingProxy): Implement.
2003-01-03 Eric Blake <ebb9@email.byu.edu>
* java/util/TreeMap.java (fabricateTree): Fix off-by-one error.

View File

@ -1,6 +1,6 @@
// Connection.java - Implementation of HttpURLConnection for http protocol.
/* Copyright (C) 1999, 2000 Free Software Foundation
/* Copyright (C) 1999, 2000, 2003 Free Software Foundation
This file is part of libgcj.
@ -25,10 +25,11 @@ import java.util.Enumeration;
/**
* Written using on-line Java Platform 1.2 API Specification, as well
* as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
* Status: Minimal subset of functionality. Proxies and Redirects
* not yet handled. FileNameMap handling needs to be considered.
* useCaches, ifModifiedSince, and allowUserInteraction need
* consideration as well as doInput and doOutput.
* Status: Minimal subset of functionality. Proxies only partially
* handled; Redirects not yet handled. FileNameMap handling needs to
* be considered. useCaches, ifModifiedSince, and
* allowUserInteraction need consideration as well as doInput and
* doOutput.
*/
class Connection extends HttpURLConnection
@ -40,6 +41,33 @@ class Connection extends HttpURLConnection
private Vector hdrVec = new Vector();
private BufferedInputStream bufferedIn;
private static int proxyPort = 80;
private static boolean proxyInUse = false;
private static String proxyHost = null;
static
{
// Recognize some networking properties listed at
// http://java.sun.com/j2se/1.4/docs/guide/net/properties.html.
String port = null;
proxyHost = System.getProperty("http.proxyHost");
if (proxyHost != null)
{
proxyInUse = true;
if ((port = System.getProperty("http.proxyPort")) != null)
{
try
{
proxyPort = Integer.parseInt(port);
}
catch (Throwable t)
{
// Nothing.
}
}
}
}
public Connection(URL url)
{
super(url);
@ -85,12 +113,20 @@ class Connection extends HttpURLConnection
// Get address and port number.
int port;
InetAddress destAddr = InetAddress.getByName(url.getHost());
if ((port = url.getPort()) == -1)
port = 80;
if (proxyInUse)
{
port = proxyPort;
sock = new Socket(proxyHost, port);
}
else
{
InetAddress destAddr = InetAddress.getByName(url.getHost());
if ((port = url.getPort()) == -1)
port = 80;
// Open socket and output stream.
sock = new Socket(destAddr, port);
}
// Open socket and output stream.
sock = new Socket(destAddr, port);
PrintWriter out = new PrintWriter(sock.getOutputStream());
// Send request including any request properties that were set.
@ -123,10 +159,9 @@ class Connection extends HttpURLConnection
}
}
// TODO: public boolean usingProxy()
public boolean usingProxy()
{
return false;
return proxyInUse;
}
// Override default method in URLConnection.