--- old/src/java.base/share/classes/sun/net/www/protocol/http/HttpURLConnection.java 2019-10-29 12:39:52.000000000 +0000 +++ new/src/java.base/share/classes/sun/net/www/protocol/http/HttpURLConnection.java 2019-10-29 12:39:52.000000000 +0000 @@ -312,6 +312,8 @@ 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; @@ -320,7 +322,6 @@ /* output stream to server */ protected PrintStream ps = null; - /* buffered error stream */ private InputStream errorStream = null; @@ -1240,6 +1241,7 @@ } } + usingProxy = usingProxy || usingProxyInternal(); ps = (PrintStream)http.getOutputStream(); } catch (IOException e) { throw e; @@ -2917,7 +2919,7 @@ * 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 @@ -3020,13 +3022,31 @@ } } - 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";