public final class HttpProperties
extends java.lang.Object
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 and 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.
|
Modifier and Type | Method and 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.
|
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)
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 managerpublic HttpProperties(okhttp3.OkHttpClient sharedHttpClient, java.util.Map<java.lang.String,java.lang.String> defaultHeaders, HeadersTransformer headersTransformer)
sharedHttpClient
- an existing HTTP client instancedefaultHeaders
- headers to add to all requestsheadersTransformer
- optional callback to modify headerspublic static HttpProperties defaults()
public java.lang.Iterable<java.util.Map.Entry<java.lang.String,java.lang.String>> getDefaultHeaders()
HeadersTransformer
, if any.toHeadersBuilder()
public java.lang.Iterable<java.util.Map.Entry<java.lang.String,java.lang.String>> getTransformedDefaultHeaders()
HeadersTransformer
, if any.toHeadersBuilder()
public HeadersTransformer getHeadersTransformer()
HeadersTransformer
or nulltoHeadersBuilder()
public okhttp3.OkHttpClient getSharedHttpClient()
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).
public void applyToHttpClientBuilder(okhttp3.OkHttpClient.Builder builder)
SDK components that use HttpProperties
should check getSharedHttpClient()
first before attempting to build their own client. The applyToHttpClientBuilder(okhttp3.OkHttpClient.Builder)
method will not provide a correct configuration if a shared client was specified.
builder
- the client builderpublic okhttp3.OkHttpClient.Builder toHttpClientBuilder()
SDK components that use HttpProperties
should check getSharedHttpClient()
first before attempting to build their own client. The toHttpClientBuilder()
method
will not provide a correct configuration if a shared client was specified.
public okhttp3.Headers.Builder toHeadersBuilder()
HeadersTransformer
, if any.public static void shutdownHttpClient(okhttp3.OkHttpClient client)
client
- the client to stop