Package org.eclipse.jgit.transport.http

## Interface HttpConnection

All Known Implementing Classes:
  `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

### Field Summary

Fields
`static int` `HTTP_FORBIDDEN`
`static int` `HTTP_NOT_FOUND`
`static int` `HTTP_OK`
`static int` `HTTP_UNAUTHORIZED`

### Method Summary

All Methods Instance Methods Abstract Methods
`void` `configure​(KeyManager[] km, TrustManager[] tm, SecureRandom random)` Configure the connection so that it can be used for https communication.
`void` `connect()`
`int` `getContentLength()`
`String` `getContentType()`
`String` `getHeaderField​(String name)`
`Map<String,​List<String>>` `getHeaderFields()`
`InputStream` `getInputStream()`
`OutputStream` `getOutputStream()`
`String` `getRequestMethod()`
`int` `getResponseCode()`
`String` `getResponseMessage()`
`URL` `getURL()`
`void` `setChunkedStreamingMode​(int chunklen)`
`void` `setConnectTimeout​(int timeout)`
`void` `setDoOutput​(boolean dooutput)`
`void` `setFixedLengthStreamingMode​(int contentLength)`
`void` `setHostnameVerifier​(HostnameVerifier hostnameverifier)` Set the `HostnameVerifier` used during https communication
`void` `setInstanceFollowRedirects​(boolean followRedirects)`
`void` `setReadTimeout​(int timeout)`
`void` `setRequestMethod​(String method)`
`void` `setRequestProperty​(String key, String value)`
`void` `setUseCaches​(boolean usecaches)`
`boolean` `usingProxy()`

### Field Detail

#### HTTP_OK

    static final int HTTP_OK

See Also:
  `HttpURLConnection.HTTP_OK`, Constant Field Values

#### HTTP_NOT_FOUND

    static final int HTTP_NOT_FOUND

See Also:
  `HttpURLConnection.HTTP_NOT_FOUND`, Constant Field Values

#### HTTP_UNAUTHORIZED

    static final int HTTP_UNAUTHORIZED

See Also:
  `HttpURLConnection.HTTP_UNAUTHORIZED`, Constant Field Values

#### HTTP_FORBIDDEN

    static final int HTTP_FORBIDDEN

See Also:
  `HttpURLConnection.HTTP_FORBIDDEN`, Constant Field Values

### Method Detail

#### getResponseCode

    int getResponseCode()
                 throws IOException

Returns:
  the HTTP Status-Code, or -1
Throws:
  `IOException`
See Also:
  `HttpURLConnection.getResponseCode()`

#### getURL

    URL getURL()

Returns:
  the URL.
See Also:
  `URLConnection.getURL()`

#### getResponseMessage

    String getResponseMessage()
                       throws IOException

Returns:
  the HTTP response message, or `null`
Throws:
  `IOException`
See Also:
  `HttpURLConnection.getResponseMessage()`

#### getHeaderFields

    Map<String,​List<String>> getHeaderFields()

Returns:
  a Map of header fields
See Also:
  `URLConnection.getHeaderFields()`

#### setRequestProperty

    void setRequestProperty​(String key,
                            String value)

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​(String method)
                   throws ProtocolException

Parameters:
  `method` - the HTTP method
Throws:
  `ProtocolException` - if the method cannot be reset or if the requested method isn't valid for HTTP.
See Also:
  `HttpURLConnection.setRequestMethod(String)`

#### setUseCaches

    void setUseCaches​(boolean usecaches)

Parameters:
  `usecaches` - a `boolean` indicating whether or not to allow caching
See Also:
  `URLConnection.setUseCaches(boolean)`

#### setConnectTimeout

    void setConnectTimeout​(int timeout)

Parameters:
  `timeout` - an `int` that specifies the connect timeout value in milliseconds
See Also:
  `URLConnection.setConnectTimeout(int)`

#### setReadTimeout

    void setReadTimeout​(int timeout)

Parameters:
  `timeout` - an `int` that specifies the timeout value to be used in milliseconds
See Also:
  `URLConnection.setReadTimeout(int)`

#### getContentType

    String getContentType()

Returns:
  the content type of the resource that the URL references, or `null` if not known.
See Also:
  `URLConnection.getContentType()`

#### getInputStream

    InputStream getInputStream()
                        throws IOException

Returns:
  an input stream that reads from this open connection.
Throws:
  `IOException` - if an I/O error occurs while creating the input stream.
See Also:
  `URLConnection.getInputStream()`

#### getHeaderField

    String getHeaderField​(String name)

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)`

#### getContentLength

    int getContentLength()

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)

Parameters:
  `followRedirects` - a `boolean` indicating whether or not to follow HTTP redirects.
See Also:
  `HttpURLConnection.setInstanceFollowRedirects(boolean)`

#### setDoOutput

    void setDoOutput​(boolean dooutput)

Parameters:
  `dooutput` - the new value.
See Also:
  `URLConnection.setDoOutput(boolean)`

#### setFixedLengthStreamingMode

    void setFixedLengthStreamingMode​(int contentLength)

Parameters:
  `contentLength` - The number of bytes which will be written to the OutputStream.
See Also:
  `HttpURLConnection.setFixedLengthStreamingMode(int)`

#### getOutputStream

    OutputStream getOutputStream()
                          throws IOException

Returns:
  an output stream that writes to this connection.
Throws:
  `IOException`
See Also:
  `URLConnection.getOutputStream()`

#### setChunkedStreamingMode

    void setChunkedStreamingMode​(int chunklen)

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

    String getRequestMethod()

Returns:
  the HTTP request method
See Also:
  `HttpURLConnection.getRequestMethod()`

#### usingProxy

    boolean usingProxy()

Returns:
  a boolean indicating if the connection is using a proxy.
See Also:
  `HttpURLConnection.usingProxy()`

#### connect

    void connect()
          throws IOException

Throws:
  `IOException`
See Also:
  `URLConnection.connect()`

#### configure

    void configure​(KeyManager[] km,
                   TrustManager[] tm,
                   SecureRandom random)
            throws NoSuchAlgorithmException,
                   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:
  `NoSuchAlgorithmException`
  `KeyManagementException`

#### setHostnameVerifier

    void setHostnameVerifier​(HostnameVerifier hostnameverifier)
                      throws NoSuchAlgorithmException,
                             KeyManagementException

Set the `HostnameVerifier` used during https communication

Parameters:
  `hostnameverifier` -
Throws:
  `NoSuchAlgorithmException`
  `KeyManagementException`