Interface HttpConnection

  • All Known Implementing Classes:
    HttpClientConnection, JDKHttpConnection

    public interface HttpConnection
    The interface of connections used during HTTP communication. This interface is that subset of the interface exposed by HttpURLConnection which is used by JGit
    Since:
    3.3
    • Method Detail

      • getResponseCode

        int getResponseCode()
                     throws java.io.IOException
        Get response code
        Returns:
        the HTTP Status-Code, or -1
        Throws:
        java.io.IOException
        See Also:
        HttpURLConnection.getResponseCode()
      • getURL

        java.net.URL getURL()
        Get URL
        Returns:
        the URL.
        See Also:
        URLConnection.getURL()
      • getResponseMessage

        java.lang.String getResponseMessage()
                                     throws java.io.IOException
        Get response message
        Returns:
        the HTTP response message, or null
        Throws:
        java.io.IOException
        See Also:
        HttpURLConnection.getResponseMessage()
      • getHeaderFields

        java.util.Map<java.lang.String,​java.util.List<java.lang.String>> getHeaderFields()
        Get map of header fields
        Returns:
        a Map of header fields
        See Also:
        URLConnection.getHeaderFields()
      • setRequestProperty

        void setRequestProperty​(java.lang.String key,
                                java.lang.String value)
        Set request property
        Parameters:
        key - the keyword by which the request is known (e.g., " Accept").
        value - the value associated with it.
        See Also:
        URLConnection.setRequestProperty(String, String)
      • setRequestMethod

        void setRequestMethod​(java.lang.String method)
                       throws java.net.ProtocolException
        Set request method
        Parameters:
        method - the HTTP method
        Throws:
        java.net.ProtocolException - if the method cannot be reset or if the requested method isn't valid for HTTP.
        java.net.ProtocolException - if any.
        See Also:
        HttpURLConnection.setRequestMethod(String)
      • setUseCaches

        void setUseCaches​(boolean usecaches)
        Set if to use caches
        Parameters:
        usecaches - a boolean indicating whether or not to allow caching
        See Also:
        URLConnection.setUseCaches(boolean)
      • setConnectTimeout

        void setConnectTimeout​(int timeout)
        Set connect timeout
        Parameters:
        timeout - an int that specifies the connect timeout value in milliseconds
        See Also:
        URLConnection.setConnectTimeout(int)
      • setReadTimeout

        void setReadTimeout​(int timeout)
        Set read timeout
        Parameters:
        timeout - an int that specifies the timeout value to be used in milliseconds
        See Also:
        URLConnection.setReadTimeout(int)
      • getContentType

        java.lang.String getContentType()
        Get content type
        Returns:
        the content type of the resource that the URL references, or null if not known.
        See Also:
        URLConnection.getContentType()
      • getInputStream

        java.io.InputStream getInputStream()
                                    throws java.io.IOException
        Get input stream
        Returns:
        an input stream that reads from this open connection.
        Throws:
        java.io.IOException - if an I/O error occurs while creating the input stream.
        java.io.IOException - if any.
        See Also:
        URLConnection.getInputStream()
      • getHeaderField

        java.lang.String getHeaderField​(@NonNull
                                        java.lang.String name)
        Get header field. According to {@link RFC 2616} header field names are case insensitive. Header fields defined as a comma separated list can have multiple header fields with the same field name. This method only returns one of these header fields. If you want the union of all values of all multiple header fields with the same field name then use getHeaderFields(String)
        Parameters:
        name - the name of a header field.
        Returns:
        the value of the named header field, or null if there is no such field in the header.
        See Also:
        URLConnection.getHeaderField(String)
      • getHeaderFields

        java.util.List<java.lang.String> getHeaderFields​(@NonNull
                                                         java.lang.String name)
        Get all values of given header field. According to {@link RFC 2616} header field names are case insensitive. Header fields defined as a comma separated list can have multiple header fields with the same field name. This method does not validate if the given header field is defined as a comma separated list.
        Parameters:
        name - the name of a header field.
        Returns:
        the list of values of the named header field
        Since:
        5.2
      • getContentLength

        int getContentLength()
        Get content length
        Returns:
        the content length of the resource that this connection's URL references, -1 if the content length is not known, or if the content length is greater than Integer.MAX_VALUE.
        See Also:
        URLConnection.getContentLength()
      • setInstanceFollowRedirects

        void setInstanceFollowRedirects​(boolean followRedirects)
        Set whether or not to follow HTTP redirects.
        Parameters:
        followRedirects - a boolean indicating whether or not to follow HTTP redirects.
        See Also:
        HttpURLConnection.setInstanceFollowRedirects(boolean)
      • setDoOutput

        void setDoOutput​(boolean dooutput)
        Set if to do output
        Parameters:
        dooutput - the new value.
        See Also:
        URLConnection.setDoOutput(boolean)
      • setFixedLengthStreamingMode

        void setFixedLengthStreamingMode​(int contentLength)
        Set fixed length streaming mode
        Parameters:
        contentLength - The number of bytes which will be written to the OutputStream.
        See Also:
        HttpURLConnection.setFixedLengthStreamingMode(int)
      • getOutputStream

        java.io.OutputStream getOutputStream()
                                      throws java.io.IOException
        Get output stream
        Returns:
        an output stream that writes to this connection.
        Throws:
        java.io.IOException
        See Also:
        URLConnection.getOutputStream()
      • setChunkedStreamingMode

        void setChunkedStreamingMode​(int chunklen)
        Set chunked streaming mode
        Parameters:
        chunklen - The number of bytes to write in each chunk. If chunklen is less than or equal to zero, a default value will be used.
        See Also:
        HttpURLConnection.setChunkedStreamingMode(int)
      • getRequestMethod

        java.lang.String getRequestMethod()
        Get request method
        Returns:
        the HTTP request method
        See Also:
        HttpURLConnection.getRequestMethod()
      • usingProxy

        boolean usingProxy()
        Whether we use a proxy
        Returns:
        a boolean indicating if the connection is using a proxy.
        See Also:
        HttpURLConnection.usingProxy()
      • connect

        void connect()
              throws java.io.IOException
        Connect
        Throws:
        java.io.IOException
        See Also:
        URLConnection.connect()
      • configure

        void configure​(javax.net.ssl.KeyManager[] km,
                       javax.net.ssl.TrustManager[] tm,
                       java.security.SecureRandom random)
                throws java.security.NoSuchAlgorithmException,
                       java.security.KeyManagementException
        Configure the connection so that it can be used for https communication.
        Parameters:
        km - the keymanager managing the key material used to authenticate the local SSLSocket to its peer
        tm - the trustmanager responsible for managing the trust material that is used when making trust decisions, and for deciding whether credentials presented by a peer should be accepted.
        random - the source of randomness for this generator or null. See SSLContext.init(KeyManager[], TrustManager[], SecureRandom)
        Throws:
        java.security.NoSuchAlgorithmException
        java.security.KeyManagementException
      • setHostnameVerifier

        void setHostnameVerifier​(javax.net.ssl.HostnameVerifier hostnameverifier)
                          throws java.security.NoSuchAlgorithmException,
                                 java.security.KeyManagementException
        Set the HostnameVerifier used during https communication
        Parameters:
        hostnameverifier - a HostnameVerifier object.
        Throws:
        java.security.NoSuchAlgorithmException
        java.security.KeyManagementException