Class HttpSupport

java.lang.Object
org.eclipse.jgit.util.HttpSupport

public class HttpSupport extends Object
Extra utilities to support usage of HTTP.
  • Field Details

  • Constructor Details

    • HttpSupport

      private HttpSupport()
  • Method Details

    • encode

      public static void encode(StringBuilder urlstr, String key)
      URL encode a value string into an output buffer.
      Parameters:
      urlstr - the output buffer.
      key - value which must be encoded to protected special characters.
    • response

      public static int response(HttpConnection c) throws IOException
      Get the HTTP response code from the request.

      Roughly the same as c.getResponseCode() but the ConnectException is translated to be more understandable.

      Parameters:
      c - connection the code should be obtained from.
      Returns:
      r HTTP status code, usually 200 to indicate success. See HttpConnection for other defined constants.
      Throws:
      IOException - communications error prevented obtaining the response code.
      Since:
      3.3
    • response

      public static int response(HttpURLConnection c) throws IOException
      Get the HTTP response code from the request.

      Roughly the same as c.getResponseCode() but the ConnectException is translated to be more understandable.

      Parameters:
      c - connection the code should be obtained from.
      Returns:
      r HTTP status code, usually 200 to indicate success. See HttpConnection for other defined constants.
      Throws:
      IOException - communications error prevented obtaining the response code.
    • responseHeader

      public static String responseHeader(HttpConnection c, String headerName) throws IOException
      Extract a HTTP header from the response.
      Parameters:
      c - connection the header should be obtained from.
      headerName - the header name
      Returns:
      the header value
      Throws:
      IOException - communications error prevented obtaining the header.
      Since:
      4.7
    • proxyFor

      public static Proxy proxyFor(ProxySelector proxySelector, URL u) throws ConnectException
      Determine the proxy server (if any) needed to obtain a URL.
      Parameters:
      proxySelector - proxy support for the caller.
      u - location of the server caller wants to talk to.
      Returns:
      proxy to communicate with the supplied URL.
      Throws:
      ConnectException - the proxy could not be computed as the supplied URL could not be read. This failure should never occur.
    • disableSslVerify

      public static void disableSslVerify(HttpConnection conn) throws IOException
      Disable SSL and hostname verification for given HTTP connection
      Parameters:
      conn - a HttpConnection object.
      Throws:
      IOException
      Since:
      4.3
    • configureTLS

      public static void configureTLS(SSLSocket socket)
      Enables all supported TLS protocol versions on the socket given. If system property "https.protocols" is set, only protocols specified there are enabled.

      This is primarily a mechanism to deal with using TLS on IBM JDK. IBM JDK returns sockets that support all TLS protocol versions but have only the one specified in the context enabled. Oracle or OpenJDK return sockets that have all available protocols enabled already, up to the one specified.

      SSLContext.getInstance() OpenJDK IDM JDK
      "TLS" Supported: TLSv1, TLSV1.1, TLSv1.2 (+ TLSv1.3)
      Enabled: TLSv1, TLSV1.1, TLSv1.2 (+ TLSv1.3)
      Supported: TLSv1, TLSV1.1, TLSv1.2
      Enabled: TLSv1
      "TLSv1.2" Supported: TLSv1, TLSV1.1, TLSv1.2
      Enabled: TLSv1, TLSV1.1, TLSv1.2
      Supported: TLSv1, TLSV1.1, TLSv1.2
      Enabled: TLSv1.2
      Parameters:
      socket - to configure
      Since:
      5.7
      See Also:
    • getConfiguredProtocols

      private static Set<String> getConfiguredProtocols()
    • getProperty

      private static String getProperty(String property)
    • scanToken

      public static int scanToken(String header, int from)
      Scan a RFC 7230 token as it appears in HTTP headers.
      Parameters:
      header - to scan in
      from - index in header to start scanning at
      Returns:
      the index after the token, that is, on the first non-token character or header.length
      Throws:
      IndexOutOfBoundsException - if from < 0 or from > header.length()
      Since:
      5.10
      See Also: