From 9c91c80bb7595b799dc5c653de60f9c9d5898d14 Mon Sep 17 00:00:00 2001 From: Joerg Brunsmann Date: Fri, 3 Jan 2003 18:05:00 +0000 Subject: [PATCH] Connection.java (proxyPort, [...]): New static fields. 2003-01-03 Joerg Brunsmann * gnu/gcj/protocol/http/Connection.java (proxyPort, proxyInUse, proxyHost): New static fields. (): Initialize new fields. (connect): Use proxy if necessary. (usingProxy): Implement. From-SVN: r60846 --- libjava/ChangeLog | 8 +++ libjava/gnu/gcj/protocol/http/Connection.java | 59 +++++++++++++++---- 2 files changed, 55 insertions(+), 12 deletions(-) diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 6b07d3fcc4f..14893f95be2 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,11 @@ +2003-01-03 Joerg Brunsmann + + * gnu/gcj/protocol/http/Connection.java (proxyPort, proxyInUse, + proxyHost): New static fields. + (): Initialize new fields. + (connect): Use proxy if necessary. + (usingProxy): Implement. + 2003-01-03 Eric Blake * java/util/TreeMap.java (fabricateTree): Fix off-by-one error. diff --git a/libjava/gnu/gcj/protocol/http/Connection.java b/libjava/gnu/gcj/protocol/http/Connection.java index caababa6823..1a6fc0105f9 100644 --- a/libjava/gnu/gcj/protocol/http/Connection.java +++ b/libjava/gnu/gcj/protocol/http/Connection.java @@ -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.