Class HttpsURLConnectionImpl


public final class HttpsURLConnectionImpl
extends HttpsURLConnection
  • Constructor Details

    • HttpsURLConnectionImpl

      public HttpsURLConnectionImpl​(URL url, OkHttpClient client)
  • Method Details

    • getCipherSuite

      public String getCipherSuite()
      Description copied from class: HttpsURLConnection
      Returns the name of the cipher suite negotiated during the SSL handshake.
      Specified by:
      getCipherSuite in class HttpsURLConnection
      Returns:
      the name of the cipher suite negotiated during the SSL handshake.
    • getLocalCertificates

      public Certificate[] getLocalCertificates()
      Description copied from class: HttpsURLConnection
      Returns the list of local certificates used during the handshake. These certificates were sent to the peer.
      Specified by:
      getLocalCertificates in class HttpsURLConnection
      Returns:
      Returns the list of certificates used during the handshake with the local identity certificate followed by CAs, or null if no certificates were used during the handshake.
    • getServerCertificates

      public Certificate[] getServerCertificates() throws SSLPeerUnverifiedException
      Description copied from class: HttpsURLConnection
      Return the list of certificates identifying the peer during the handshake.
      Specified by:
      getServerCertificates in class HttpsURLConnection
      Returns:
      the list of certificates identifying the peer with the peer's identity certificate followed by CAs.
      Throws:
      SSLPeerUnverifiedException - if the identity of the peer has not been verified..
    • getPeerPrincipal

      public Principal getPeerPrincipal() throws SSLPeerUnverifiedException
      Description copied from class: HttpsURLConnection
      Returns the Principal identifying the peer.
      Overrides:
      getPeerPrincipal in class HttpsURLConnection
      Returns:
      the Principal identifying the peer.
      Throws:
      SSLPeerUnverifiedException - if the identity of the peer has not been verified.
    • getLocalPrincipal

      public Principal getLocalPrincipal()
      Description copied from class: HttpsURLConnection
      Returns the Principal used to identify the local host during the handshake.
      Overrides:
      getLocalPrincipal in class HttpsURLConnection
      Returns:
      the Principal used to identify the local host during the handshake, or null if none was used.
    • getHttpEngine

      public HttpEngine getHttpEngine()
    • disconnect

      public void disconnect()
      Description copied from class: HttpURLConnection
      Releases this connection so that its resources may be either reused or closed.

      Unlike other Java implementations, this will not necessarily close socket connections that can be reused. You can disable all connection reuse by setting the http.keepAlive system property to false before issuing any HTTP requests.

      Specified by:
      disconnect in class HttpURLConnection
    • getErrorStream

      public InputStream getErrorStream()
      Description copied from class: HttpURLConnection
      Returns an input stream from the server in the case of an error such as the requested file has not been found on the remote server. This stream can be used to read the data the server will send back.
      Overrides:
      getErrorStream in class HttpURLConnection
      Returns:
      the error input stream returned by the server.
    • getRequestMethod

      public String getRequestMethod()
      Description copied from class: HttpURLConnection
      Returns the request method which will be used to make the request to the remote HTTP server. All possible methods of this HTTP implementation is listed in the class definition.
      Overrides:
      getRequestMethod in class HttpURLConnection
      Returns:
      the request method string.
      See Also:
      HttpURLConnection.method, HttpURLConnection.setRequestMethod(java.lang.String)
    • getResponseCode

      public int getResponseCode() throws IOException
      Description copied from class: HttpURLConnection
      Returns the response code returned by the remote HTTP server.
      Overrides:
      getResponseCode in class HttpURLConnection
      Returns:
      the response code, -1 if no valid response code.
      Throws:
      IOException - if there is an IO error during the retrieval.
      See Also:
      HttpURLConnection.getResponseMessage()
    • getResponseMessage

      public String getResponseMessage() throws IOException
      Description copied from class: HttpURLConnection
      Returns the response message returned by the remote HTTP server.
      Overrides:
      getResponseMessage in class HttpURLConnection
      Returns:
      the response message. null if no such response exists.
      Throws:
      IOException - if there is an error during the retrieval.
      See Also:
      HttpURLConnection.getResponseCode()
    • setRequestMethod

      public void setRequestMethod​(String method) throws ProtocolException
      Description copied from class: HttpURLConnection
      Sets the request command which will be sent to the remote HTTP server. This method can only be called before the connection is made.
      Overrides:
      setRequestMethod in class HttpURLConnection
      Parameters:
      method - the string representing the method to be used.
      Throws:
      ProtocolException - if this is called after connected, or the method is not supported by this HTTP implementation.
      See Also:
      HttpURLConnection.getRequestMethod(), HttpURLConnection.method
    • usingProxy

      public boolean usingProxy()
      Description copied from class: HttpURLConnection
      Returns whether this connection uses a proxy server or not.
      Specified by:
      usingProxy in class HttpURLConnection
      Returns:
      true if this connection passes a proxy server, false otherwise.
    • getInstanceFollowRedirects

      public boolean getInstanceFollowRedirects()
      Description copied from class: HttpURLConnection
      Returns whether this connection follows redirects.
      Overrides:
      getInstanceFollowRedirects in class HttpURLConnection
      Returns:
      true if this connection follows redirects, false otherwise.
    • setInstanceFollowRedirects

      public void setInstanceFollowRedirects​(boolean followRedirects)
      Description copied from class: HttpURLConnection
      Sets whether this connection follows redirects.
      Overrides:
      setInstanceFollowRedirects in class HttpURLConnection
      Parameters:
      followRedirects - true if this connection will follows redirects, false otherwise.
    • connect

      public void connect() throws IOException
      Description copied from class: URLConnection
      Opens a connection to the resource. This method will not reconnect to a resource after the initial connection has been closed.
      Specified by:
      connect in class URLConnection
      Throws:
      IOException - if an error occurs while connecting to the resource.
    • getAllowUserInteraction

      public boolean getAllowUserInteraction()
      Description copied from class: URLConnection
      Returns allowUserInteraction. Unused by Android.
      Overrides:
      getAllowUserInteraction in class URLConnection
    • getContent

      public Object getContent() throws IOException
      Description copied from class: URLConnection
      Returns an object representing the content of the resource this URLConnection is connected to. First, it attempts to get the content type from the method getContentType() which looks at the response header field "Content-Type". If none is found it will guess the content type from the filename extension. If that fails the stream itself will be used to guess the content type.
      Overrides:
      getContent in class URLConnection
      Returns:
      the content representing object.
      Throws:
      IOException - if an error occurs obtaining the content.
    • getContent

      public Object getContent​(Class[] types) throws IOException
      Description copied from class: URLConnection
      Returns an object representing the content of the resource this URLConnection is connected to. First, it attempts to get the content type from the method getContentType() which looks at the response header field "Content-Type". If none is found it will guess the content type from the filename extension. If that fails the stream itself will be used to guess the content type. The content type must match with one of the list types.
      Overrides:
      getContent in class URLConnection
      Parameters:
      types - the list of acceptable content types.
      Returns:
      the content representing object or null if the content type does not match with one of the specified types.
      Throws:
      IOException - if an error occurs obtaining the content.
    • getContentEncoding

      public String getContentEncoding()
      Description copied from class: HttpURLConnection
      Returns the encoding used to transmit the response body over the network. This is null or "identity" if the content was not encoded, or "gzip" if the body was gzip compressed. Most callers will be more interested in the content type, which may also include the content's character encoding.
      Overrides:
      getContentEncoding in class HttpURLConnection
      Returns:
      the value of the response header field content-encoding.
    • getContentLength

      public int getContentLength()
      Description copied from class: URLConnection
      Returns the content length in bytes specified by the response header field content-length or -1 if this field is not set.
      Overrides:
      getContentLength in class URLConnection
      Returns:
      the value of the response header field content-length.
    • getContentType

      public String getContentType()
      Description copied from class: URLConnection
      Returns the MIME-type of the content specified by the response header field content-type or null if type is unknown.
      Overrides:
      getContentType in class URLConnection
      Returns:
      the value of the response header field content-type.
    • getDate

      public long getDate()
      Description copied from class: URLConnection
      Returns the timestamp when this response has been sent as a date in milliseconds since January 1, 1970 GMT or 0 if this timestamp is unknown.
      Overrides:
      getDate in class URLConnection
      Returns:
      the sending timestamp of the current response.
    • getDefaultUseCaches

      public boolean getDefaultUseCaches()
      Description copied from class: URLConnection
      Returns the default setting whether this connection allows using caches.
      Overrides:
      getDefaultUseCaches in class URLConnection
      Returns:
      the value of the default setting defaultUseCaches.
      See Also:
      URLConnection.useCaches
    • getDoInput

      public boolean getDoInput()
      Description copied from class: URLConnection
      Returns the value of the option doInput which specifies whether this connection allows to receive data.
      Overrides:
      getDoInput in class URLConnection
      Returns:
      true if this connection allows input, false otherwise.
      See Also:
      URLConnection.doInput
    • getDoOutput

      public boolean getDoOutput()
      Description copied from class: URLConnection
      Returns the value of the option doOutput which specifies whether this connection allows to send data.
      Overrides:
      getDoOutput in class URLConnection
      Returns:
      true if this connection allows output, false otherwise.
      See Also:
      URLConnection.doOutput
    • getExpiration

      public long getExpiration()
      Description copied from class: URLConnection
      Returns the timestamp when this response will be expired in milliseconds since January 1, 1970 GMT or 0 if this timestamp is unknown.
      Overrides:
      getExpiration in class URLConnection
      Returns:
      the value of the response header field expires.
    • getHeaderField

      public String getHeaderField​(int pos)
      Description copied from class: URLConnection
      Returns the header value at the field position pos or null if the header has fewer than pos fields. The base implementation of this method returns always null.

      Some implementations (notably HttpURLConnection) include a mapping for the null key; in HTTP's case, this maps to the HTTP status line and is treated as being at position 0 when indexing into the header fields.

      Overrides:
      getHeaderField in class URLConnection
      Parameters:
      pos - the field position of the response header.
      Returns:
      the value of the field at position pos.
    • getHeaderFields

      public Map<String,​List<String>> getHeaderFields()
      Description copied from class: URLConnection
      Returns an unmodifiable map of the response-header fields and values. The response-header field names are the key values of the map. The map values are lists of header field values associated with a particular key name.

      Some implementations (notably HttpURLConnection) include a mapping for the null key; in HTTP's case, this maps to the HTTP status line and is treated as being at position 0 when indexing into the header fields.

      Overrides:
      getHeaderFields in class URLConnection
      Returns:
      the response-header representing generic map.
    • getRequestProperties

      public Map<String,​List<String>> getRequestProperties()
      Description copied from class: URLConnection
      Returns an unmodifiable map of general request properties used by this connection. The request property names are the key values of the map. The map values are lists of property values of the corresponding key name.
      Overrides:
      getRequestProperties in class URLConnection
      Returns:
      the request-property representing generic map.
    • addRequestProperty

      public void addRequestProperty​(String field, String newValue)
      Description copied from class: URLConnection
      Adds the given property to the request header. Existing properties with the same name will not be overwritten by this method.
      Overrides:
      addRequestProperty in class URLConnection
      Parameters:
      field - the request property field name to add.
      newValue - the value of the property which is to add.
    • getHeaderField

      public String getHeaderField​(String key)
      Description copied from class: URLConnection
      Returns the value of the header field specified by key or null if there is no field with this name. The base implementation of this method returns always null.

      Some implementations (notably HttpURLConnection) include a mapping for the null key; in HTTP's case, this maps to the HTTP status line and is treated as being at position 0 when indexing into the header fields.

      Overrides:
      getHeaderField in class URLConnection
      Parameters:
      key - the name of the header field.
      Returns:
      the value of the header field.
    • getHeaderFieldDate

      public long getHeaderFieldDate​(String field, long defaultValue)
      Description copied from class: HttpURLConnection
      Returns the date value in milliseconds since 01.01.1970, 00:00h corresponding to the header field field. The defaultValue will be returned if no such field can be found in the response header.
      Overrides:
      getHeaderFieldDate in class HttpURLConnection
      Parameters:
      field - the header field name.
      defaultValue - the default value to use if the specified header field wont be found.
      Returns:
      the header field represented in milliseconds since January 1, 1970 GMT.
    • getHeaderFieldInt

      public int getHeaderFieldInt​(String field, int defaultValue)
      Description copied from class: URLConnection
      Returns the specified header value as a number. Returns the defaultValue if no such header field could be found or the value could not be parsed as an Integer.
      Overrides:
      getHeaderFieldInt in class URLConnection
      Parameters:
      field - the header field name whose value is needed.
      defaultValue - the default value if no field has been found.
      Returns:
      the value of the specified header field as a number.
    • getHeaderFieldKey

      public String getHeaderFieldKey​(int position)
      Description copied from class: URLConnection
      Returns the name of the header field at the given position posn or null if there are fewer than posn fields. The base implementation of this method returns always null.

      Some implementations (notably HttpURLConnection) include a mapping for the null key; in HTTP's case, this maps to the HTTP status line and is treated as being at position 0 when indexing into the header fields.

      Overrides:
      getHeaderFieldKey in class URLConnection
      Parameters:
      position - the position of the header field which has to be returned.
      Returns:
      the header field name at the given position.
    • getIfModifiedSince

      public long getIfModifiedSince()
      Description copied from class: URLConnection
      Returns the point of time since when the data must be modified to be transmitted. Some protocols transmit data only if it has been modified more recently than a particular time.
      Overrides:
      getIfModifiedSince in class URLConnection
      Returns:
      the time in milliseconds since January 1, 1970 GMT.
      See Also:
      URLConnection.ifModifiedSince
    • getInputStream

      public InputStream getInputStream() throws IOException
      Description copied from class: URLConnection
      Returns an InputStream for reading data from the resource pointed by this URLConnection. It throws an UnknownServiceException by default. This method must be overridden by its subclasses.
      Overrides:
      getInputStream in class URLConnection
      Returns:
      the InputStream to read data from.
      Throws:
      IOException - if no InputStream could be created.
    • getLastModified

      public long getLastModified()
      Description copied from class: URLConnection
      Returns the value of the response header field last-modified or 0 if this value is not set.
      Overrides:
      getLastModified in class URLConnection
      Returns:
      the value of the last-modified header field.
    • getOutputStream

      public OutputStream getOutputStream() throws IOException
      Description copied from class: URLConnection
      Returns an OutputStream for writing data to this URLConnection. It throws an UnknownServiceException by default. This method must be overridden by its subclasses.
      Overrides:
      getOutputStream in class URLConnection
      Returns:
      the OutputStream to write data.
      Throws:
      IOException - if no OutputStream could be created.
    • getPermission

      public Permission getPermission() throws IOException
      Description copied from class: HttpURLConnection
      Returns the permission object (in this case SocketPermission) with the host and the port number as the target name and "resolve, connect" as the action list. If the port number of this URL instance is lower than 0 the port will be set to 80.
      Overrides:
      getPermission in class HttpURLConnection
      Returns:
      the permission object required for this connection.
      Throws:
      IOException - if an IO exception occurs during the creation of the permission object.
    • getRequestProperty

      public String getRequestProperty​(String field)
      Description copied from class: URLConnection
      Returns the value of the request header property specified by {code field} or null if there is no field with this name. The base implementation of this method returns always null.
      Overrides:
      getRequestProperty in class URLConnection
      Parameters:
      field - the name of the request header property.
      Returns:
      the value of the property.
    • getURL

      public URL getURL()
      Description copied from class: URLConnection
      Returns the URL represented by this URLConnection.
      Overrides:
      getURL in class URLConnection
      Returns:
      the URL of this connection.
    • getUseCaches

      public boolean getUseCaches()
      Description copied from class: URLConnection
      Returns the value of the flag which specifies whether this URLConnection allows to use caches.
      Overrides:
      getUseCaches in class URLConnection
      Returns:
      true if using caches is allowed, false otherwise.
    • setAllowUserInteraction

      public void setAllowUserInteraction​(boolean newValue)
      Description copied from class: URLConnection
      Sets allowUserInteraction. Unused by Android.
      Overrides:
      setAllowUserInteraction in class URLConnection
    • setDefaultUseCaches

      public void setDefaultUseCaches​(boolean newValue)
      Description copied from class: URLConnection
      Sets the default value for the flag indicating whether this connection allows to use caches. Existing URLConnections are unaffected.
      Overrides:
      setDefaultUseCaches in class URLConnection
      Parameters:
      newValue - the default value of the flag to be used for new connections.
      See Also:
      URLConnection.useCaches
    • setDoInput

      public void setDoInput​(boolean newValue)
      Description copied from class: URLConnection
      Sets the flag indicating whether this URLConnection allows input. It cannot be set after the connection is established.
      Overrides:
      setDoInput in class URLConnection
      Parameters:
      newValue - the new value for the flag to be set.
      See Also:
      URLConnection.doInput
    • setDoOutput

      public void setDoOutput​(boolean newValue)
      Description copied from class: URLConnection
      Sets the flag indicating whether this URLConnection allows output. It cannot be set after the connection is established.
      Overrides:
      setDoOutput in class URLConnection
      Parameters:
      newValue - the new value for the flag to be set.
      See Also:
      URLConnection.doOutput
    • setIfModifiedSince

      public void setIfModifiedSince​(long newValue)
      Description copied from class: URLConnection
      Sets the point of time since when the data must be modified to be transmitted. Some protocols transmit data only if it has been modified more recently than a particular time. The data will be transmitted regardless of its timestamp if this option is set to 0.
      Overrides:
      setIfModifiedSince in class URLConnection
      Parameters:
      newValue - the time in milliseconds since January 1, 1970 GMT.
      See Also:
      URLConnection.ifModifiedSince
    • setRequestProperty

      public void setRequestProperty​(String field, String newValue)
      Description copied from class: URLConnection
      Sets the value of the specified request header field. The value will only be used by the current URLConnection instance. This method can only be called before the connection is established.
      Overrides:
      setRequestProperty in class URLConnection
      Parameters:
      field - the request header field to be set.
      newValue - the new value of the specified property.
    • setUseCaches

      public void setUseCaches​(boolean newValue)
      Description copied from class: URLConnection
      Sets the flag indicating whether this connection allows to use caches or not. This method can only be called prior to the connection establishment.
      Overrides:
      setUseCaches in class URLConnection
      Parameters:
      newValue - the value of the flag to be set.
      See Also:
      URLConnection.useCaches
    • setConnectTimeout

      public void setConnectTimeout​(int timeoutMillis)
      Description copied from class: URLConnection
      Sets the maximum time in milliseconds to wait while connecting. Connecting to a server will fail with a SocketTimeoutException if the timeout elapses before a connection is established. The default value of 0 causes us to do a blocking connect. This does not mean we will never time out, but it probably means you'll get a TCP timeout after several minutes.

      Warning: if the hostname resolves to multiple IP addresses, this client will try each in RFC 3484 order. If connecting to each of these addresses fails, multiple timeouts will elapse before the connect attempt throws an exception. Host names that support both IPv6 and IPv4 always have at least 2 IP addresses.

      Overrides:
      setConnectTimeout in class URLConnection
    • getConnectTimeout

      public int getConnectTimeout()
      Description copied from class: URLConnection
      Returns the connect timeout in milliseconds. (See {#setConnectTimeout}.)
      Overrides:
      getConnectTimeout in class URLConnection
    • setReadTimeout

      public void setReadTimeout​(int timeoutMillis)
      Description copied from class: URLConnection
      Sets the maximum time to wait for an input stream read to complete before giving up. Reading will fail with a SocketTimeoutException if the timeout elapses before data becomes available. The default value of 0 disables read timeouts; read attempts will block indefinitely.
      Overrides:
      setReadTimeout in class URLConnection
      Parameters:
      timeoutMillis - the read timeout in milliseconds. Non-negative.
    • getReadTimeout

      public int getReadTimeout()
      Description copied from class: URLConnection
      Returns the read timeout in milliseconds, or 0 if reads never timeout.
      Overrides:
      getReadTimeout in class URLConnection
    • toString

      public String toString()
      Description copied from class: URLConnection
      Returns the string representation containing the name of this class and the URL.
      Overrides:
      toString in class URLConnection
      Returns:
      the string representation of this URLConnection instance.
    • setFixedLengthStreamingMode

      public void setFixedLengthStreamingMode​(int contentLength)
      Description copied from class: HttpURLConnection
      Equivalent to setFixedLengthStreamingMode((long) contentLength), but available on earlier versions of Android and limited to 2 GiB.
      Overrides:
      setFixedLengthStreamingMode in class HttpURLConnection
    • setChunkedStreamingMode

      public void setChunkedStreamingMode​(int chunkLength)
      Description copied from class: HttpURLConnection
      Stream a request body whose length is not known in advance. Old HTTP/1.0 only servers may not support this mode.

      When HTTP chunked encoding is used, the stream is divided into chunks, each prefixed with a header containing the chunk's size. Setting a large chunk length requires a large internal buffer, potentially wasting memory. Setting a small chunk length increases the number of bytes that must be transmitted because of the header on every chunk. Most caller should use 0 to get the system default.

      Overrides:
      setChunkedStreamingMode in class HttpURLConnection
      Parameters:
      chunkLength - the length to use, or 0 for the default chunk length.
      See Also:
      HttpURLConnection.setFixedLengthStreamingMode(long)
    • setHostnameVerifier

      public void setHostnameVerifier​(HostnameVerifier hostnameVerifier)
      Description copied from class: HttpsURLConnection
      Sets the hostname verifier for this instance.
      Overrides:
      setHostnameVerifier in class HttpsURLConnection
      Parameters:
      hostnameVerifier - the hostname verifier for this instance.
    • getHostnameVerifier

      public HostnameVerifier getHostnameVerifier()
      Description copied from class: HttpsURLConnection
      Returns the hostname verifier used by this instance.
      Overrides:
      getHostnameVerifier in class HttpsURLConnection
      Returns:
      the hostname verifier used by this instance.
    • setSSLSocketFactory

      public void setSSLSocketFactory​(SSLSocketFactory sslSocketFactory)
      Description copied from class: HttpsURLConnection
      Sets the SSL socket factory for this instance.
      Overrides:
      setSSLSocketFactory in class HttpsURLConnection
      Parameters:
      sslSocketFactory - the SSL socket factory to be used by this instance.
    • getSSLSocketFactory

      public SSLSocketFactory getSSLSocketFactory()
      Description copied from class: HttpsURLConnection
      Returns the SSL socket factory used by this instance.
      Overrides:
      getSSLSocketFactory in class HttpsURLConnection
      Returns:
      the SSL socket factory used by this instance.