Skip to content

Commit

Permalink
OkHttp options WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
wkal-pubnub committed Jan 22, 2025
1 parent e4a6925 commit ffdd097
Show file tree
Hide file tree
Showing 8 changed files with 263 additions and 51 deletions.
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
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ktlint = "12.1.0"
dokka = "1.9.20"
kotlinx_datetime = "0.6.1"
kotlinx_coroutines = "1.9.0"
pubnub_js = "8.4.1"
pubnub_js = "8.6.0"
pubnub_swift = "8.3.0"

[libraries]
Expand Down
24 changes: 20 additions & 4 deletions kotlin-js-store/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -659,10 +659,26 @@ proxy-from-env@^1.1.0:
resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2"
integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==

pubnub@8.4.0:
version "8.4.0"
resolved "https://registry.yarnpkg.com/pubnub/-/pubnub-8.4.0.tgz#8a5fdd3af9783abb1de44ea4145107e296c8394d"
integrity sha512-HvkFhn4XcfR1wdJv4paX94I0TT4UBHW/vIuYnS+6XuoSx0AunJMCk5wbKnSesmdbzYUZa8Ag3H1mJQZKuyRy8Q==
pubnub@8.4.1:
version "8.4.1"
resolved "https://registry.yarnpkg.com/pubnub/-/pubnub-8.4.1.tgz#5f6f19e84d3187dc8aee0a458bd6b05e90d43e6a"
integrity sha512-mPlwVoHJDWPasZx52UfSMiPX5TATm5A+ficSogyqDqTQ4w5EQnwxH+PJdsWc0mPnlT051jM1vIISMeM0fQ30CQ==
dependencies:
agentkeepalive "^3.5.2"
buffer "^6.0.3"
cbor-js "^0.1.0"
cbor-sync "^1.0.4"
form-data "^4.0.0"
lil-uuid "^0.1.1"
node-fetch "^2.7.0"
proxy-agent "^6.3.0"
react-native-url-polyfill "^2.0.0"
text-encoding "^0.7.0"

pubnub@8.6.0:
version "8.6.0"
resolved "https://registry.yarnpkg.com/pubnub/-/pubnub-8.6.0.tgz#75524e7ed3653090652d160ce83ac089362a0379"
integrity sha512-LBCglooxiLkNT3ArUOvSJnLKK6/QdeshWY60IWlSQ+SkXlzEjt74wAnX5XriEXKsmza2yw9mFGG6+B5SlczRzA==
dependencies:
agentkeepalive "^3.5.2"
buffer "^6.0.3"
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

0 comments on commit ffdd097

Please sign in to comment.