Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wkal/expose okhttp client #330

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: Tests

on:
push:
branches-ignore:
- master
workflow_dispatch:

jobs:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/run-validations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: Validations

on:
push:
branches-ignore:
- master
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.pubnub.api.retry.RetryableEndpointGroup
import okhttp3.Authenticator
import okhttp3.CertificatePinner
import okhttp3.ConnectionSpec
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import org.slf4j.LoggerFactory
import java.net.Proxy
Expand Down Expand Up @@ -71,6 +72,10 @@ class PNConfigurationImpl(
)
),
override val managePresenceListManually: Boolean = false,
override val baseOkHttpClient: OkHttpClient? = null,
override val subscribeOkHttpConfigureAction: ((OkHttpClient.Builder) -> Unit)? = null,
override val nonSubscribeOkHttpConfigureAction: ((OkHttpClient.Builder) -> Unit)? = null,
override val filesOkHttpConfigureAction: ((OkHttpClient.Builder) -> Unit)? = null,
) : PNConfiguration {
companion object {
const val DEFAULT_DEDUPE_SIZE = 100
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.pubnub.api.retry.RetryConfiguration
import okhttp3.Authenticator
import okhttp3.CertificatePinner
import okhttp3.ConnectionSpec
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import java.net.Proxy
import java.net.ProxySelector
Expand All @@ -16,6 +17,47 @@ import javax.net.ssl.SSLSocketFactory
import javax.net.ssl.X509ExtendedTrustManager

actual interface PNConfiguration {
/**
* The base [OkHttpClient] instance that will be used to preconfigure PubNub SDK's internal clients.
*
* Please note that the internal clients will share the dispatcher and connection pool with the provided client.
*
* @see [subscribeOkHttpConfigureAction]
* @see [nonSubscribeOkHttpConfigureAction]
* @see [filesOkHttpConfigureAction]
*/
val baseOkHttpClient: OkHttpClient?

/**
* Use this callback to configure any options on the [OkHttpClient] instance that will be used for Subscribe requests.
*
* Setting this option disables reading values from [logVerbosity], [httpLoggingInterceptor], [sslSocketFactory],
* [connectionSpec], [hostnameVerifier], [proxy], [proxySelector], [proxyAuthenticator] and [certificatePinner] for
* the instance of `OkHttpClient` servicing Subscribe requests. Those options should be set using the
* [subscribeOkHttpConfigureAction] instead.
*/
val subscribeOkHttpConfigureAction: ((OkHttpClient.Builder) -> Unit)?

/**
* Use this callback to configure any options on the [OkHttpClient] instance that will be used for requests other than Subscribe or File upload/download.
*
* Setting this option disables reading values from [logVerbosity], [httpLoggingInterceptor], [sslSocketFactory],
* [connectionSpec], [hostnameVerifier], [proxy], [proxySelector], [proxyAuthenticator] and [certificatePinner] for
* the instance of `OkHttpClient` servicing requests other than Subscribe and File upload/download. Those options
* should be set using the [nonSubscribeOkHttpConfigureAction] instead.
*/
val nonSubscribeOkHttpConfigureAction: ((OkHttpClient.Builder) -> Unit)?

/**
* Use this callback to configure any options on the [OkHttpClient] instance that will be used for File upload/download requests.
*
* Setting this option disables reading values from [logVerbosity], [httpLoggingInterceptor], [sslSocketFactory],
* [connectionSpec], [hostnameVerifier], [proxy], [proxySelector], [proxyAuthenticator] and [certificatePinner] for
* the instance of `OkHttpClient` servicing File upload/download requests. Those options
* should be set using the [filesOkHttpConfigureAction] instead.
*/
val filesOkHttpConfigureAction: ((OkHttpClient.Builder) -> Unit)?

/**
* The user ID that the PubNub client will use.
*/
Expand Down Expand Up @@ -77,6 +119,9 @@ actual interface PNConfiguration {
/**
* Set to [PNLogVerbosity.BODY] to enable logging of network traffic, otherwise se to [PNLogVerbosity.NONE].
*/
@Deprecated(
message = "Use `subscribeOkHttpConfigureAction`, `nonSubscribeOkHttpConfigureAction`, or `filesOkHttpConfigureAction` to configure the OkHttp client."
)
actual val logVerbosity: PNLogVerbosity

/**
Expand All @@ -103,7 +148,7 @@ actual interface PNConfiguration {
val heartbeatInterval: Int

/**
* The subscribe request timeout.
* The subscribe read timeout.
*
* The value is in seconds.
*
Expand Down Expand Up @@ -147,6 +192,9 @@ actual interface PNConfiguration {
*
* Defaults to 10.
*/
@Deprecated(
message = "Use `subscribeOkHttpConfigureAction`, `nonSubscribeOkHttpConfigureAction`, or `filesOkHttpConfigureAction` to configure the OkHttp client."
)
val nonSubscribeReadTimeout: Int

/**
Expand Down Expand Up @@ -212,48 +260,75 @@ actual interface PNConfiguration {
*
* @see [Proxy]
*/
@Deprecated(
message = "Use `subscribeOkHttpConfigureAction`, `nonSubscribeOkHttpConfigureAction`, or `filesOkHttpConfigureAction` to configure the OkHttp client."
)
val proxy: Proxy?

/**
* @see [ProxySelector]
*/
@Deprecated(
message = "Use `subscribeOkHttpConfigureAction`, `nonSubscribeOkHttpConfigureAction`, or `filesOkHttpConfigureAction` to configure the OkHttp client."
)
val proxySelector: ProxySelector?

/**
* @see [Authenticator]
*/
@Deprecated(
message = "Use `subscribeOkHttpConfigureAction`, `nonSubscribeOkHttpConfigureAction`, or `filesOkHttpConfigureAction` to configure the OkHttp client."
)
val proxyAuthenticator: Authenticator?

/**
* @see [CertificatePinner]
*/
@Deprecated(
message = "Use `subscribeOkHttpConfigureAction`, `nonSubscribeOkHttpConfigureAction`, or `filesOkHttpConfigureAction` to configure the OkHttp client."
)
val certificatePinner: CertificatePinner?

/**
* Sets a custom [HttpLoggingInterceptor] for logging network traffic.
*
* @see [HttpLoggingInterceptor]
*/
@Deprecated(
message = "Use `subscribeOkHttpConfigureAction`, `nonSubscribeOkHttpConfigureAction`, or `filesOkHttpConfigureAction` to configure the OkHttp client."
)
val httpLoggingInterceptor: HttpLoggingInterceptor?

/**
* @see [SSLSocketFactory]
*/
@Deprecated(
message = "Use `subscribeOkHttpConfigureAction`, `nonSubscribeOkHttpConfigureAction`, or `filesOkHttpConfigureAction` to configure the OkHttp client."
)
val sslSocketFactory: SSLSocketFactory?

/**
* @see [X509ExtendedTrustManager]
*/
@Deprecated(
message = "Use `subscribeOkHttpConfigureAction`, `nonSubscribeOkHttpConfigureAction`, or `filesOkHttpConfigureAction` to configure the OkHttp client."
)
val x509ExtendedTrustManager: X509ExtendedTrustManager?

/**
* @see [okhttp3.ConnectionSpec]
*/
@Deprecated(
message = "Use `subscribeOkHttpConfigureAction`, `nonSubscribeOkHttpConfigureAction`, or `filesOkHttpConfigureAction` to configure the OkHttp client."
)
val connectionSpec: ConnectionSpec?

/**
* @see [javax.net.ssl.HostnameVerifier]
*/
@Deprecated(
message = "Use `subscribeOkHttpConfigureAction`, `nonSubscribeOkHttpConfigureAction`, or `filesOkHttpConfigureAction` to configure the OkHttp client."
)
val hostnameVerifier: HostnameVerifier?

/**
Expand Down Expand Up @@ -505,6 +580,9 @@ actual interface PNConfiguration {
/**
* @see [okhttp3.Dispatcher.setMaxRequestsPerHost]
*/
@Deprecated(
message = "Use `subscribeOkHttpConfigureAction`, `nonSubscribeOkHttpConfigureAction`, or `filesOkHttpConfigureAction` to configure the OkHttp client."
)
var maximumConnections: Int?

/**
Expand Down Expand Up @@ -594,6 +672,41 @@ actual interface PNConfiguration {
*/
var managePresenceListManually: Boolean

/**
* The base [OkHttpClient] instance that will be used to preconfigure PubNub SDK's internal `OKHttpClients`.
*/
var baseOkHttpClient: OkHttpClient?

/**
* Use this callback to configure any options on the [OkHttpClient] instance that will be used for Subscribe requests.
*
* Setting this option disables reading values from [logVerbosity], [httpLoggingInterceptor], [sslSocketFactory],
* [connectionSpec], [hostnameVerifier], [proxy], [proxySelector], [proxyAuthenticator] and [certificatePinner] for
* the instance of `OkHttpClient` servicing Subscribe requests. Those options should be set using the
* [subscribeOkHttpConfigureAction] instead.
*/
var subscribeOkHttpConfigureAction: ((OkHttpClient.Builder) -> Unit)?

/**
* Use this callback to configure any options on the [OkHttpClient] instance that will be used for requests other than Subscribe or File upload/download.
*
* Setting this option disables reading values from [logVerbosity], [httpLoggingInterceptor], [sslSocketFactory],
* [connectionSpec], [hostnameVerifier], [proxy], [proxySelector], [proxyAuthenticator] and [certificatePinner] for
* the instance of `OkHttpClient` servicing requests other than Subscribe and File upload/download. Those options
* should be set using the [nonSubscribeOkHttpConfigureAction] instead.
*/
var nonSubscribeOkHttpConfigureAction: ((OkHttpClient.Builder) -> Unit)?

/**
* Use this callback to configure any options on the [OkHttpClient] instance that will be used for File upload/download requests.
*
* Setting this option disables reading values from [logVerbosity], [httpLoggingInterceptor], [sslSocketFactory],
* [connectionSpec], [hostnameVerifier], [proxy], [proxySelector], [proxyAuthenticator] and [certificatePinner] for
* the instance of `OkHttpClient` servicing File upload/download requests. Those options
* should be set using the [filesOkHttpConfigureAction] instead.
*/
var filesOkHttpConfigureAction: ((OkHttpClient.Builder) -> Unit)?

/**
* Create a [PNConfiguration] object with values from this builder.
*/
Expand Down Expand Up @@ -701,6 +814,36 @@ interface PNConfigurationOverride {
*/
var nonSubscribeReadTimeout: Int

/**
* Use this callback to configure any options on the [OkHttpClient] instance that will be used for Subscribe requests.
*
* Setting this option disables reading values from [logVerbosity], [httpLoggingInterceptor], [sslSocketFactory],
* [connectionSpec], [hostnameVerifier], [proxy], [proxySelector], [proxyAuthenticator] and [certificatePinner] for
* the instance of `OkHttpClient` servicing Subscribe requests. Those options should be set using the
* [subscribeOkHttpConfigureAction] instead.
*/
var subscribeOkHttpConfigureAction: ((OkHttpClient.Builder) -> Unit)?

/**
* Use this callback to configure any options on the [OkHttpClient] instance that will be used for requests other than Subscribe or File upload/download.
*
* Setting this option disables reading values from [logVerbosity], [httpLoggingInterceptor], [sslSocketFactory],
* [connectionSpec], [hostnameVerifier], [proxy], [proxySelector], [proxyAuthenticator] and [certificatePinner] for
* the instance of `OkHttpClient` servicing requests other than Subscribe and File upload/download. Those options
* should be set using the [nonSubscribeOkHttpConfigureAction] instead.
*/
var nonSubscribeOkHttpConfigureAction: ((OkHttpClient.Builder) -> Unit)?

/**
* Use this callback to configure any options on the [OkHttpClient] instance that will be used for File upload/download requests.
*
* Setting this option disables reading values from [logVerbosity], [httpLoggingInterceptor], [sslSocketFactory],
* [connectionSpec], [hostnameVerifier], [proxy], [proxySelector], [proxyAuthenticator] and [certificatePinner] for
* the instance of `OkHttpClient` servicing File upload/download requests. Those options
* should be set using the [filesOkHttpConfigureAction] instead.
*/
var filesOkHttpConfigureAction: ((OkHttpClient.Builder) -> Unit)?

/**
* Create a [PNConfiguration] object with values from this builder.
*/
Expand Down
Loading
Loading