Class HttpProperties
- java.lang.Object
-
- com.launchdarkly.sdk.internal.http.HttpProperties
-
public final class HttpProperties extends java.lang.Object
Internal container for HTTP parameters used by SDK components. Includes logic for creating an OkHttp client.This is separate from any public HTTP configuration/builder classes that are part of the SDK API. Those are transformed into this when the SDK is constructing components. The public API does not reference any OkHttp classes, but this internal class does.
-
-
Constructor Summary
Constructors Constructor Description HttpProperties(long connectTimeoutMillis, java.util.Map<java.lang.String,java.lang.String> defaultHeaders, HeadersTransformer headersTransformer, java.net.Proxy proxy, okhttp3.Authenticator proxyAuth, javax.net.SocketFactory socketFactory, long socketTimeoutMillis, javax.net.ssl.SSLSocketFactory sslSocketFactory, javax.net.ssl.X509TrustManager trustManager)
Constructs an instance.HttpProperties(okhttp3.OkHttpClient sharedHttpClient, java.util.Map<java.lang.String,java.lang.String> defaultHeaders, HeadersTransformer headersTransformer)
Constructs an instance with a preconfigured shared HTTP client.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
applyToHttpClientBuilder(okhttp3.OkHttpClient.Builder builder)
Applies the configured properties to an OkHttp client builder.static HttpProperties
defaults()
Returns a minimal set of properties.java.lang.Iterable<java.util.Map.Entry<java.lang.String,java.lang.String>>
getDefaultHeaders()
Returns an immutable view of the default headers.HeadersTransformer
getHeadersTransformer()
Returns the callback for transforming headers, if any.okhttp3.OkHttpClient
getSharedHttpClient()
Returns a preconfigured shared HTTP client, if one was defined.java.lang.Iterable<java.util.Map.Entry<java.lang.String,java.lang.String>>
getTransformedDefaultHeaders()
Returns an immutable view of the headers to add to a request.static void
shutdownHttpClient(okhttp3.OkHttpClient client)
Attempts to completely shut down an OkHttp client.okhttp3.Headers.Builder
toHeadersBuilder()
Returns an OkHttp Headers builder initialized with the default headers.okhttp3.OkHttpClient.Builder
toHttpClientBuilder()
Returns an OkHttp client builder initialized with the configured properties.
-
-
-
Constructor Detail
-
HttpProperties
public HttpProperties(long connectTimeoutMillis, java.util.Map<java.lang.String,java.lang.String> defaultHeaders, HeadersTransformer headersTransformer, java.net.Proxy proxy, okhttp3.Authenticator proxyAuth, javax.net.SocketFactory socketFactory, long socketTimeoutMillis, javax.net.ssl.SSLSocketFactory sslSocketFactory, javax.net.ssl.X509TrustManager trustManager)
Constructs an instance.- Parameters:
connectTimeoutMillis
- connection timeout millisecondsdefaultHeaders
- headers to add to all requestsheadersTransformer
- optional callback to modify headersproxy
- optional proxyproxyAuth
- optional proxy authenticatorsocketFactory
- optional socket factorysocketTimeoutMillis
- socket timeout millisecondssslSocketFactory
- optional SSL socket factorytrustManager
- optional SSL trust manager
-
HttpProperties
public HttpProperties(okhttp3.OkHttpClient sharedHttpClient, java.util.Map<java.lang.String,java.lang.String> defaultHeaders, HeadersTransformer headersTransformer)
Constructs an instance with a preconfigured shared HTTP client.- Parameters:
sharedHttpClient
- an existing HTTP client instancedefaultHeaders
- headers to add to all requestsheadersTransformer
- optional callback to modify headers
-
-
Method Detail
-
defaults
public static HttpProperties defaults()
Returns a minimal set of properties.- Returns:
- a default instance
-
getDefaultHeaders
public java.lang.Iterable<java.util.Map.Entry<java.lang.String,java.lang.String>> getDefaultHeaders()
Returns an immutable view of the default headers. This does not include applying the configuredHeadersTransformer
, if any.- Returns:
- the default headers
- See Also:
toHeadersBuilder()
-
getTransformedDefaultHeaders
public java.lang.Iterable<java.util.Map.Entry<java.lang.String,java.lang.String>> getTransformedDefaultHeaders()
Returns an immutable view of the headers to add to a request. This includes applying the configuredHeadersTransformer
, if any.- Returns:
- the default headers
- See Also:
toHeadersBuilder()
-
getHeadersTransformer
public HeadersTransformer getHeadersTransformer()
Returns the callback for transforming headers, if any.- Returns:
- a
HeadersTransformer
or null - See Also:
toHeadersBuilder()
-
getSharedHttpClient
public okhttp3.OkHttpClient getSharedHttpClient()
Returns a preconfigured shared HTTP client, if one was defined.SDK components that use
HttpProperties
should check this method first before attempting to build their own client. If it returns a non-null value, they should use that client; in that case, no other properties except the default headers are relevant, and they should not take ownership of the client (that is, do not close the client when the component is closed).- Returns:
- an HTTP client or null
-
applyToHttpClientBuilder
public void applyToHttpClientBuilder(okhttp3.OkHttpClient.Builder builder)
Applies the configured properties to an OkHttp client builder.SDK components that use
HttpProperties
should checkgetSharedHttpClient()
first before attempting to build their own client. TheapplyToHttpClientBuilder(okhttp3.OkHttpClient.Builder)
method will not provide a correct configuration if a shared client was specified.- Parameters:
builder
- the client builder
-
toHttpClientBuilder
public okhttp3.OkHttpClient.Builder toHttpClientBuilder()
Returns an OkHttp client builder initialized with the configured properties.SDK components that use
HttpProperties
should checkgetSharedHttpClient()
first before attempting to build their own client. ThetoHttpClientBuilder()
method will not provide a correct configuration if a shared client was specified.- Returns:
- a client builder
-
toHeadersBuilder
public okhttp3.Headers.Builder toHeadersBuilder()
Returns an OkHttp Headers builder initialized with the default headers. This includes calling the configuredHeadersTransformer
, if any.- Returns:
- a Headers builder
-
shutdownHttpClient
public static void shutdownHttpClient(okhttp3.OkHttpClient client)
Attempts to completely shut down an OkHttp client.- Parameters:
client
- the client to stop
-
-