Class HttpClient

    • Constructor Detail

      • HttpClient

        public HttpClient()
        Create a new http client with the default executor.
      • HttpClient

        public HttpClient​(@Nonnull
                          ExecutorType executorType)
        Create a new http client with the given executor type.
        Some executor types may not be supported by your Java version. Make sure to check ExecutorType.isAvailable() before using them.
        Parameters:
        executorType - The executor type to use
      • HttpClient

        public HttpClient​(@Nonnull
                          java.util.function.Function<HttpClient,​RequestExecutor> executorSupplier)
        Create a new http client with the given executor.
        You'll only need this if you want to use a custom executor. For using an official executor use ExecutorType with HttpClient(ExecutorType).
        Parameters:
        executorSupplier - The supplier for the executor to use
    • Method Detail

      • setExecutor

        public HttpClient setExecutor​(@Nonnull
                                      java.util.function.Function<HttpClient,​RequestExecutor> executorSupplier)
        Set the executor to use for all requests.
        Parameters:
        executorSupplier - The supplier for the executor to use
      • getCookieManager

        @Nullable
        public java.net.CookieManager getCookieManager()
        Returns:
        The cookie manager
      • setCookieManager

        public HttpClient setCookieManager​(@Nullable
                                           java.net.CookieManager cookieManager)
        Set the cookie manager to use for all requests.
        If this is null no cookies will be used.
        Parameters:
        cookieManager - The cookie manager to use
        Returns:
        This instance for chaining
      • isFollowRedirects

        public boolean isFollowRedirects()
        Returns:
        Whether redirects should be followed
      • setFollowRedirects

        public HttpClient setFollowRedirects​(boolean followRedirects)
        Set whether redirects should be followed.
        Parameters:
        followRedirects - Whether redirects should be followed
        Returns:
        This instance for chaining
      • getConnectTimeout

        public int getConnectTimeout()
        Returns:
        The connect timeout for all requests in milliseconds
      • setConnectTimeout

        public HttpClient setConnectTimeout​(int connectTimeout)
        Set the connect timeout for all requests.
        Parameters:
        connectTimeout - The connect timeout in milliseconds
        Returns:
        This instance for chaining
      • getReadTimeout

        public int getReadTimeout()
        Returns:
        The read timeout for all requests in milliseconds
      • setReadTimeout

        public HttpClient setReadTimeout​(int readTimeout)
        Set the read timeout for all requests.
        Parameters:
        readTimeout - The read timeout in milliseconds
        Returns:
        This instance for chaining
      • getRetryHandler

        @Nonnull
        public RetryHandler getRetryHandler()
        Returns:
        The retry handler
      • setRetryHandler

        public HttpClient setRetryHandler​(@Nonnull
                                          RetryHandler retryHandler)
        Set the retry handler for all requests.
        Parameters:
        retryHandler - The retry handler
        Returns:
        This instance for chaining
      • getProxyHandler

        @Nonnull
        public ProxyHandler getProxyHandler()
        Returns:
        The proxy handler
      • setProxyHandler

        public void setProxyHandler​(@Nonnull
                                    ProxyHandler proxyHandler)
        Set the proxy handler for all requests.
        Parameters:
        proxyHandler - The proxy handler
      • execute

        public <R> R execute​(HttpRequest request,
                             HttpResponseHandler<R> responseHandler)
                      throws java.io.IOException
        Execute a request and pass the response to the response handler.
        The return value of the response handler will be returned.
        Type Parameters:
        R - The return type of the response handler
        Parameters:
        request - The request to execute
        responseHandler - The response handler
        Returns:
        The return value of the response handler
        Throws:
        java.io.IOException - If an I/O error occurs
      • execute

        public HttpResponse execute​(HttpRequest request)
                             throws java.io.IOException
        Execute a request and return the response.
        Parameters:
        request - The request to execute
        Returns:
        The response
        Throws:
        java.io.IOException - If an I/O error occurs
        RetryExceededException - If the maximum header retry count was exceeded
        java.lang.IllegalStateException - If the maximum retry count was exceeded but no exception was thrown