Top Description Inners Fields Constructors Methods
sun.net.www.protocol.http

public Class HttpURLConnection

Additional top-level class in compilation unit: EmptyInputStream.

extends HttpURLConnection
Class Inheritance
Known Direct Subclasses
sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection
Imports
java.security.PrivilegedAction, .AccessController, .PrivilegedExceptionAction, .PrivilegedActionException, java.util.Arrays, .ArrayList, .Collections, .Date, .Map, .List, .Locale, .StringTokenizer, .Iterator, .HashSet, .HashMap, .Set, .StringJoiner, .TimeZone, .Objects, .Properties, java.net.URL, .URLConnection, .ProtocolException, .HttpRetryException, .PasswordAuthentication, .Authenticator, .HttpCookie, .InetAddress, .UnknownHostException, .SocketTimeoutException, .SocketPermission, .Proxy, .ProxySelector, .URI, .InetSocketAddress, .CookieHandler, .ResponseCache, .CacheResponse, .SecureCacheResponse, .CacheRequest, .URLPermission, .Authenticator.RequestorType, .MalformedURLException, java.io.*, jdk.internal.access.JavaNetHttpCookieAccess, .SharedSecrets, sun.net.NetProperties, .NetworkClient, sun.net.util.IPAddressUtil, sun.net.www.*, sun.net.www.http.HttpClient, .PosterOutputStream, .ChunkedInputStream, .ChunkedOutputStream, sun.util.logging.PlatformLogger, java.text.SimpleDateFormat, java.nio.ByteBuffer, java.util.concurrent.locks.ReentrantLock, sun.security.action.GetIntegerAction, .GetPropertyAction

A class to represent an HTTP connection to a remote object.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
pack-priv class
pack-priv class
public static enum

Field Summary

Modifier and TypeField and Description
pack-priv static final String
private static final boolean
protected volatile AuthCacheImpl
protected volatile Authenticator
private Object
private static final int
private MessageHeader
private InputStream
protected CacheResponse
private final ResponseCache
pack-priv byte[]
private boolean
private final ReentrantLock
private int
private CookieHandler
pack-priv AuthenticationInfo
pack-priv AuthenticationInfo
private static HttpAuthenticator
defaultAuth

Deprecated
pack-priv static final int
pack-priv DigestAuthentication.Parameters
pack-priv static final Set<String>
disabledProxyingSchemes

A, possibly empty, set of authentication schemes that are disabled when proxying plain HTTP ( not HTTPS ).

pack-priv static final Set<String>
disabledTunnelingSchemes

A, possibly empty, set of authentication schemes that are disabled when setting up a tunnel for HTTPS ( HTTP CONNECT ).

private boolean
private boolean
pack-priv String
private static final boolean
private InputStream
private static final String[]
private static final String[]
private boolean
private Map<String, List<String>>
protected Handler
protected HttpClient
pack-priv static final String
pack-priv static final String
private InputStream
protected Proxy
pack-priv boolean
pack-priv boolean
private static final PlatformLogger
pack-priv static final int
pack-priv boolean
private PosterOutputStream
pack-priv String
protected PrintStream
private int
private Exception
private Exception
private MessageHeader
pack-priv String
private MessageHeader
private static final String[]
private static final Set<String>
private static final String
private static final String
private static final String
private HttpClient
pack-priv String
private static final String
private static final String
private boolean
private boolean
private SocketPermission
private HttpURLConnection.StreamingOutputStream
private static final int
private boolean
private boolean
private HttpURLConnection.TunnelState
private boolean
public static final String
private String
private String
private final MessageHeader
private volatile boolean
pack-priv static final boolean
pack-priv static final boolean
pack-priv static final String
Inherited from java.net.HttpURLConnection:
chunkLengthfixedContentLengthfixedContentLengthLongHTTP_ACCEPTEDHTTP_BAD_GATEWAYHTTP_BAD_METHODHTTP_BAD_REQUESTHTTP_CLIENT_TIMEOUTHTTP_CONFLICTHTTP_CREATEDHTTP_ENTITY_TOO_LARGEHTTP_FORBIDDENHTTP_GATEWAY_TIMEOUTHTTP_GONEHTTP_INTERNAL_ERRORHTTP_LENGTH_REQUIREDHTTP_MOVED_PERMHTTP_MOVED_TEMPHTTP_MULT_CHOICEHTTP_NO_CONTENTHTTP_NOT_ACCEPTABLEHTTP_NOT_AUTHORITATIVEHTTP_NOT_FOUNDHTTP_NOT_IMPLEMENTEDHTTP_NOT_MODIFIEDHTTP_OKHTTP_PARTIALHTTP_PAYMENT_REQUIREDHTTP_PRECON_FAILEDHTTP_PROXY_AUTHHTTP_REQ_TOO_LONGHTTP_RESETHTTP_SEE_OTHERHTTP_SERVER_ERRORHTTP_UNAUTHORIZEDHTTP_UNAVAILABLEHTTP_UNSUPPORTED_TYPEHTTP_USE_PROXYHTTP_VERSIONinstanceFollowRedirectsmethodresponseCoderesponseMessage

Constructor Summary

AccessConstructor and Description
protected
public
HttpURLConnection(URL u, String host, int port)

public
HttpURLConnection(URL u, Proxy p)

this constructor is used by other protocol handlers such as ftp that want to use http to fetch urls on their behalf.

protected

Method Summary

Modifier and TypeMethod and Description
public void
addRequestProperty(String
the keyword by which the request is known (e.g., "accept").
key
,
String
the value associated with it.
value
)

Overrides java.net.URLConnection.addRequestProperty.

Adds a general request property specified by a key-value pair.
public Object
public void
authObj(Object authObj)

private static String
private void
private void
checkResponseCredentials(boolean inClose)

private boolean
private boolean
private static URL
private void
public void
connect()

Implements abstract java.net.URLConnection.connect.

Opens a communications link to the resource referenced by this URL, if such a connection has not already been established.
pack-priv static String
public void
disconnect()

Implements abstract java.net.HttpURLConnection.disconnect.

Disconnect from the server (public API)
private void
disconnectInternal()

Disconnect from the server (for internal use)

private void
disconnectWeb()

Disconnect from the web server at the first 401 error.

public void
doTunneling()

establish a tunnel through proxy server

private void
private void
private String
filterHeaderField(String name, String value)

Returns a filtered version of the given headers value.

private boolean
private boolean
followRedirect0(String loc, int stat, URL locUrl)

public AuthCacheImpl
private IOException
getChainedException(final IOException rememberedException)

public int

Returns:

an int that indicates the connect timeout value in milliseconds
getConnectTimeout
()

Overrides java.net.URLConnection.getConnectTimeout.

Returns setting for connect timeout.
public CookieHandler
public InputStream
getErrorStream()

Overrides java.net.HttpURLConnection.getErrorStream.

Returns the error stream if the connection failed but the server sent useful data nonetheless.
private Map<String, List<String>>
public String
getHeaderField(String
the name of the header field
name
)

Overrides java.net.URLConnection.getHeaderField.

Gets a header field by name.
public String
getHeaderField(int
the index of the header field
n
)

Overrides java.net.HttpURLConnection.getHeaderField.

Gets a header field by index.
public String
getHeaderFieldKey(int
the index of the header field
n
)

Overrides java.net.HttpURLConnection.getHeaderFieldKey.

Gets a header field by index.
public Map<String, List<String>>

Returns:

a Map of header fields
getHeaderFields
()

Overrides java.net.URLConnection.getHeaderFields.

Returns an unmodifiable Map of the header fields.
private String
protected HttpCallerInfo
getHttpCallerInfo(URL url, String proxy, int port, Authenticator authenticator)

Overridden in https to also include the server certificate

protected HttpCallerInfo
getHttpCallerInfo(URL url, Authenticator authenticator)

Overridden in https to also include the server certificate

public static PlatformLogger
private AuthenticationInfo
getHttpProxyAuthentication(AuthenticationHeader authhdr)

Gets the authentication for an HTTP proxy, and applies it to the connection.

public InputStream
getInputStream()

Overrides java.net.URLConnection.getInputStream.

Returns an input stream that reads from this open connection.
private InputStream
pack-priv String
private static String
protected HttpClient
getNewHttpClient(URL url, Proxy p, int connectTimeout)

protected HttpClient
getNewHttpClient(URL url, Proxy p, int connectTimeout, boolean useCache)

public OutputStream
getOutputStream()

Overrides java.net.URLConnection.getOutputStream.

Returns an output stream that writes to this connection.
private OutputStream
public int

Returns:

an int that indicates the read timeout value in milliseconds
getReadTimeout
()

Overrides java.net.URLConnection.getReadTimeout.

Returns setting for read timeout.
public Map<String, List<String>>

Returns:

a Map of the general request properties for this connection.
getRequestProperties
()

Overrides java.net.URLConnection.getRequestProperties.

Returns an unmodifiable Map of general request properties for this connection.
public String
getRequestProperty(String
the keyword by which the request is known (e.g., "Accept").
key
)

Overrides java.net.URLConnection.getRequestProperty.

Returns the value of the named general request property for this connection.
pack-priv String
private AuthenticationInfo
getServerAuthentication(AuthenticationHeader
the AuthenticationHeader which tells what auth scheme is preferred.
authhdr
)

Gets the authentication for an HTTP server, and applies it to the connection.

pack-priv MessageHeader
private static boolean
hostsEqual(URL u1, URL u2)

private boolean
public final boolean
private boolean
private final void
lock()

private MessageHeader
private static URL
newURL(String spec)

private static URL
newURL(URL context, String spec)

public static InputStream
openConnectionCheckRedirects(URLConnection c)

opens a stream allowing redirects only to the same host.

protected void
protected void
private static PasswordAuthentication
privilegedRequestPasswordAuthentication(final Authenticator authenticator, final String host, final InetAddress addr, final int port, final String protocol, final String prompt, final String scheme, final URL url, final Authenticator.RequestorType authType)

protected void
proxiedConnect(URL url, String proxyHost, int proxyPort, boolean useCache)

private void
reset()

Reset (without disconnecting the TCP conn) in order to do another transaction with this instance

private AuthenticationInfo
resetProxyAuthentication(AuthenticationInfo proxyAuthentication, AuthenticationHeader auth)

set or reset proxy authentication info in request headers after receiving a 407 error.

private static boolean
sameDestination(URL firstURL, URL secondURL)

private static Set<String>
private void
sendCONNECTRequest()

send a CONNECT request for establishing a tunnel to proxy server

public void
public void
setAuthenticator(Authenticator
The Authenticator that should be used by this HttpURLConnection.
auth
)

Overrides java.net.HttpURLConnection.setAuthenticator.

Supplies an Authenticator to be used when authentication is requested through the HTTP protocol for this HttpURLConnection.
public void
setConnectTimeout(int
an int that specifies the connect timeout value in milliseconds
timeout
)

Overrides java.net.URLConnection.setConnectTimeout.

Sets a specified timeout value, in milliseconds, to be used when opening a communications link to the resource referenced by this URLConnection.
private void
public static void
setDefaultAuthenticator(HttpAuthenticator a)

Deprecated Use java.net.Authenticator.setDefault() instead.
protected void
setNewClient(URL
the URL being accessed
url
)

Create a new HttpClient object, bypassing the cache of HTTP client objects/connections.

protected void
setNewClient(URL
the URL being accessed
url
,
boolean
whether the cached connection should be used if present
useCache
)

Obtain a HttpsClient object.

private void
setPreemptiveProxyAuthentication(MessageHeader requests)

Sets pre-emptive proxy authentication in header

protected void
setProxiedClient(URL
the URL being accessed
url
,
String
the proxy host to use
proxyHost
,
int
the proxy port to use
proxyPort
)

Create a new HttpClient object, set up so that it uses per-instance proxying to the given HTTP proxy.

protected void
setProxiedClient(URL
the URL being accessed
url
,
String
the proxy host to use
proxyHost
,
int
the proxy port to use
proxyPort
,
boolean
whether the cached connection should be used if present
useCache
)

Obtain a HttpClient object, set up so that it uses per-instance proxying to the given HTTP proxy.

public void
setReadTimeout(int
an int that specifies the timeout value to be used in milliseconds
timeout
)

Overrides java.net.URLConnection.setReadTimeout.

Sets the read timeout to a specified timeout, in milliseconds.
public void
setRequestMethod(String
the HTTP method
method
)

Overrides java.net.HttpURLConnection.setRequestMethod.

Set the method for the URL request, one of:
  • GET
  • POST
  • HEAD
  • OPTIONS
  • PUT
  • DELETE
  • TRACE
public void
setRequestProperty(String
the keyword by which the request is known (e.g., "Accept").
key
,
String
the value to be set
value
)

Overrides java.net.URLConnection.setRequestProperty.

Sets request property.
public void
setTunnelState(HttpURLConnection.TunnelState
the state
tunnelState
)

Set the tunneling status.

public boolean
pack-priv static String

Returns:

host address without Zone Id
stripIPv6ZoneId
(String
host address (not null, not empty)
host
)

Returns the given host, without the IPv6 Zone Id, if present.

pack-priv HttpURLConnection.TunnelState

Returns:

the state
tunnelState
()

Returns the tunnel state.

private final void
pack-priv SocketPermission
URLtoSocketPermission(URL url)

if the caller has a URLPermission for connecting to the given URL, then return a SocketPermission which permits access to that destination.

public boolean
usingProxy()

Implements abstract java.net.HttpURLConnection.usingProxy.

Returns true if the established connection is using a proxy or if a proxy is specified for the inactive connection
pack-priv boolean
usingProxyInternal()

Returns true only if the established connection is using a proxy

private static void
private void
Inherited from java.net.HttpURLConnection:
getFollowRedirectsgetHeaderFieldDategetInstanceFollowRedirectsgetPermissiongetRequestMethodgetResponseCodegetResponseMessagesetChunkedStreamingModesetFixedLengthStreamingModesetFixedLengthStreamingModesetFollowRedirectssetInstanceFollowRedirects