Class OkHttpUtils

java.lang.Object
io.jenkins.plugins.restlistparam.util.OkHttpUtils

public class OkHttpUtils extends Object
  • Method Details

    • getClientWithProxyAndCache

      public static okhttp3.OkHttpClient getClientWithProxyAndCache(String httpEndpoint)
      Builds a OkHTTP client that respects any proxy set in the Jenkins 'Plugin Manager' and offers a response cache. A proxy will only be applied if the host of the httpEndpoint is NOT part of the noProxy values. The response cache is only present if the creation on disk is possible, otherwise there is none.

      The client has no connect, read or write timeout; callers bound a request with a call timeout (see getClient(String, Duration)).

      Parameters:
      httpEndpoint - the host of the endpoint will get looked up against the noProxy values
      Returns:
      OkHttpClient setup with an appropriate httpProxy value and response cache
    • getClient

      public static okhttp3.OkHttpClient getClient(String httpEndpoint, Duration callTimeout)
      Like getClientWithProxyAndCache(String), with a call timeout that covers the whole request: DNS, connecting, sending the request and reading the response body.
      Parameters:
      httpEndpoint - the host of the endpoint will get looked up against the noProxy values
      callTimeout - how long the call may take; must be positive
    • closeSharedClient

      @Terminator public static void closeSharedClient()
      Closes the response cache when Jenkins stops, so no file in the Jenkins home stays open (Windows cannot delete open files). The next request after a restart opens the cache again.
    • getCacheControl

      public static okhttp3.CacheControl getCacheControl(Integer minutesCached)