8231632: HttpURLConnection::usingProxy could specify that it may lazily evaluate the fact

Modified method description to disambiguate when false is returned and altered implementation

Reviewed-by: dfuchs, chegar, vtewari
This commit is contained in:
Julia Boes 2019-11-01 12:57:01 +00:00
parent 9c7e4bcf59
commit 012dffcd27
3 changed files with 365 additions and 5 deletions

View file

@ -312,6 +312,8 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
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 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
/* output stream to server */
protected PrintStream ps = null;
/* buffered error stream */
private InputStream errorStream = null;
@ -1240,6 +1241,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
}
}
usingProxy = usingProxy || usingProxyInternal();
ps = (PrintStream)http.getOutputStream();
} catch (IOException e) {
throw e;
@ -2917,7 +2919,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
* 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 class HttpURLConnection extends java.net.HttpURLConnection {
}
}
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";