summaryrefslogtreecommitdiff
path: root/gnu/java/net/protocol/http
diff options
context:
space:
mode:
authorMichael Koch <konqueror@gmx.de>2003-10-20 15:16:33 +0000
committerMichael Koch <konqueror@gmx.de>2003-10-20 15:16:33 +0000
commitdabf9205e1132fb5fd1aa9d1e2591cf5ecb6d221 (patch)
tree9b49b3e8edffc76072570a1975ec0a2319906ec8 /gnu/java/net/protocol/http
parent859fd0abd83b477722f9cdfc9cc7bac3708b55ac (diff)
downloadclasspath-dabf9205e1132fb5fd1aa9d1e2591cf5ecb6d221.tar.gz
2003-10-20 Michael Koch <konqueror@gmx.de>
* gnu/java/net/protocol/file/Connection.java, gnu/java/net/protocol/http/Connection.java: Some reformating.
Diffstat (limited to 'gnu/java/net/protocol/http')
-rw-r--r--gnu/java/net/protocol/http/Connection.java58
1 files changed, 51 insertions, 7 deletions
diff --git a/gnu/java/net/protocol/http/Connection.java b/gnu/java/net/protocol/http/Connection.java
index 099c3f5db..e2e2126ff 100644
--- a/gnu/java/net/protocol/http/Connection.java
+++ b/gnu/java/net/protocol/http/Connection.java
@@ -75,6 +75,35 @@ public final class Connection extends HttpURLConnection
* The socket we are connected to
*/
private Socket socket;
+
+ private static String proxyHost = null;
+ private static int proxyPort = 80;
+ private static boolean proxyInUse = false;
+
+ 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.
+ }
+ }
+ }
+ }
/**
* The InputStream for this connection.
@@ -119,12 +148,27 @@ public final class Connection extends HttpURLConnection
*/
public void connect() throws IOException
{
- // Connect up
- if (url.getPort() == -1)
- socket = new Socket(url.getHost(), 80);
- else
- socket = new Socket(url.getHost(), url.getPort());
+ // Call is ignored if already connected.
+ if (connected)
+ return;
+
+ // Get address and port number.
+ int port;
+ if (proxyInUse)
+ {
+ port = proxyPort;
+ socket = new Socket (proxyHost, port);
+ }
+ else
+ {
+ if ((port = url.getPort()) == -1)
+ port = 80;
+
+ // Open socket and output stream.
+ socket = new Socket (url.getHost(), port);
+ }
+
if (doInput)
inputStream
= new DataInputStream (new BufferedInputStream (socket.getInputStream()));
@@ -170,7 +214,7 @@ public final class Connection extends HttpURLConnection
+ " HTTP/1.1\r\n");
// Set additional HTTP headers.
- if (getRequestProperty ("host") == null)
+ if (getRequestProperty ("Host") == null)
{
setRequestProperty ("Host", url.getHost());
}
@@ -340,7 +384,7 @@ public final class Connection extends HttpURLConnection
*/
public boolean usingProxy()
{
- return false;
+ return proxyInUse;
}
/**