< prev index next >

src/java.base/share/classes/sun/net/www/protocol/http/HttpURLConnection.java

Print this page

        

@@ -310,19 +310,20 @@
     protected volatile String authenticatorKey;
 
     private CookieHandler cookieHandler;
     private final ResponseCache cacheHandler;
 
+    private volatile boolean usingProxy;
+
     // the cached response, and cached response headers and body
     protected CacheResponse cachedResponse;
     private MessageHeader cachedHeaders;
     private InputStream cachedInputStream;
 
     /* output stream to server */
     protected PrintStream ps = null;
 
-
     /* buffered error stream */
     private InputStream errorStream = null;
 
     /* User set Cookies */
     private boolean setUserCookies = true;

@@ -1238,10 +1239,11 @@
                     http = getNewHttpClient(url, instProxy, connectTimeout, false);
                     http.setReadTimeout(readTimeout);
                 }
             }
 
+            usingProxy = usingProxy || usingProxyInternal();
             ps = (PrintStream)http.getOutputStream();
         } catch (IOException e) {
             throw e;
         }
         // constructor to HTTP client calls openserver

@@ -2915,11 +2917,11 @@
      * Disconnect from the web server at the first 401 error. Do not
      * disconnect when using a proxy, a good proxy should have already
      * closed the connection to the web server.
      */
     private void disconnectWeb() throws IOException {
-        if (usingProxy() && http.isKeepingAlive()) {
+        if (usingProxyInternal() && http.isKeepingAlive()) {
             responseCode = -1;
             // clean up, particularly, skip the content part
             // of a 401 error response
             reset();
         } else {

@@ -3018,17 +3020,35 @@
         if (cachedHeaders != null) {
             cachedHeaders.reset();
         }
     }
 
-    public boolean usingProxy() {
+    /**
+     * Returns true only if the established connection is using a proxy
+     */
+    boolean usingProxyInternal() {
         if (http != null) {
             return (http.getProxyHostUsed() != null);
         }
         return false;
     }
 
+    /**
+     * Returns true if the established connection is using a proxy
+     * or if a proxy is specified for the inactive connection
+     */
+    @Override
+    public boolean usingProxy() {
+        if (usingProxy || usingProxyInternal())
+            return true;
+
+        if (instProxy != null)
+            return instProxy.type().equals(Proxy.Type.HTTP);
+
+        return false;
+    }
+
     // constant strings represent set-cookie header names
     private static final String SET_COOKIE = "set-cookie";
     private static final String SET_COOKIE2 = "set-cookie2";
 
     /**
< prev index next >