Skip to content

Commit 739e39b

Browse files
committed
OkHttp options WIP
1 parent 4f5c588 commit 739e39b

File tree

6 files changed

+242
-46
lines changed

6 files changed

+242
-46
lines changed

.github/workflows/run-tests.yml

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ name: Tests
22

33
on:
44
push:
5+
branches-ignore:
6+
- master
57
workflow_dispatch:
68

79
jobs:

.github/workflows/run-validations.yml

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ name: Validations
22

33
on:
44
push:
5+
branches-ignore:
6+
- master
57
workflow_dispatch:
68
concurrency:
79
group: ${{ github.workflow }}-${{ github.ref }}

pubnub-gson/pubnub-gson-impl/src/main/java/com/pubnub/internal/java/v2/PNConfigurationImpl.kt

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import com.pubnub.api.retry.RetryableEndpointGroup
1111
import okhttp3.Authenticator
1212
import okhttp3.CertificatePinner
1313
import okhttp3.ConnectionSpec
14+
import okhttp3.OkHttpClient
1415
import okhttp3.logging.HttpLoggingInterceptor
1516
import org.slf4j.LoggerFactory
1617
import java.net.Proxy
@@ -71,6 +72,10 @@ class PNConfigurationImpl(
7172
)
7273
),
7374
override val managePresenceListManually: Boolean = false,
75+
override val baseOkHttpClient: OkHttpClient? = null,
76+
override val subscribeOkHttpConfigureAction: ((OkHttpClient.Builder) -> Unit)? = null,
77+
override val nonSubscribeOkHttpConfigureAction: ((OkHttpClient.Builder) -> Unit)? = null,
78+
override val filesOkHttpConfigureAction: ((OkHttpClient.Builder) -> Unit)? = null,
7479
) : PNConfiguration {
7580
companion object {
7681
const val DEFAULT_DEDUPE_SIZE = 100

pubnub-kotlin/pubnub-kotlin-core-api/src/jvmMain/kotlin/com/pubnub/api/v2/PNConfiguration.kt

+144-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.pubnub.api.retry.RetryConfiguration
88
import okhttp3.Authenticator
99
import okhttp3.CertificatePinner
1010
import okhttp3.ConnectionSpec
11+
import okhttp3.OkHttpClient
1112
import okhttp3.logging.HttpLoggingInterceptor
1213
import java.net.Proxy
1314
import java.net.ProxySelector
@@ -16,6 +17,47 @@ import javax.net.ssl.SSLSocketFactory
1617
import javax.net.ssl.X509ExtendedTrustManager
1718

1819
actual interface PNConfiguration {
20+
/**
21+
* The base [OkHttpClient] instance that will be used to preconfigure PubNub SDK's internal clients.
22+
*
23+
* Please note that the internal clients will share the dispatcher and connection pool with the provided client.
24+
*
25+
* @see [subscribeOkHttpConfigureAction]
26+
* @see [nonSubscribeOkHttpConfigureAction]
27+
* @see [filesOkHttpConfigureAction]
28+
*/
29+
val baseOkHttpClient: OkHttpClient?
30+
31+
/**
32+
* Use this callback to configure any options on the [OkHttpClient] instance that will be used for Subscribe requests.
33+
*
34+
* Setting this option disables reading values from [logVerbosity], [httpLoggingInterceptor], [sslSocketFactory],
35+
* [connectionSpec], [hostnameVerifier], [proxy], [proxySelector], [proxyAuthenticator] and [certificatePinner] for
36+
* the instance of `OkHttpClient` servicing Subscribe requests. Those options should be set using the
37+
* [subscribeOkHttpConfigureAction] instead.
38+
*/
39+
val subscribeOkHttpConfigureAction: ((OkHttpClient.Builder) -> Unit)?
40+
41+
/**
42+
* Use this callback to configure any options on the [OkHttpClient] instance that will be used for requests other than Subscribe or File upload/download.
43+
*
44+
* Setting this option disables reading values from [logVerbosity], [httpLoggingInterceptor], [sslSocketFactory],
45+
* [connectionSpec], [hostnameVerifier], [proxy], [proxySelector], [proxyAuthenticator] and [certificatePinner] for
46+
* the instance of `OkHttpClient` servicing requests other than Subscribe and File upload/download. Those options
47+
* should be set using the [nonSubscribeOkHttpConfigureAction] instead.
48+
*/
49+
val nonSubscribeOkHttpConfigureAction: ((OkHttpClient.Builder) -> Unit)?
50+
51+
/**
52+
* Use this callback to configure any options on the [OkHttpClient] instance that will be used for File upload/download requests.
53+
*
54+
* Setting this option disables reading values from [logVerbosity], [httpLoggingInterceptor], [sslSocketFactory],
55+
* [connectionSpec], [hostnameVerifier], [proxy], [proxySelector], [proxyAuthenticator] and [certificatePinner] for
56+
* the instance of `OkHttpClient` servicing File upload/download requests. Those options
57+
* should be set using the [filesOkHttpConfigureAction] instead.
58+
*/
59+
val filesOkHttpConfigureAction: ((OkHttpClient.Builder) -> Unit)?
60+
1961
/**
2062
* The user ID that the PubNub client will use.
2163
*/
@@ -77,6 +119,9 @@ actual interface PNConfiguration {
77119
/**
78120
* Set to [PNLogVerbosity.BODY] to enable logging of network traffic, otherwise se to [PNLogVerbosity.NONE].
79121
*/
122+
@Deprecated(
123+
message = "Use `subscribeOkHttpConfigureAction`, `nonSubscribeOkHttpConfigureAction`, or `filesOkHttpConfigureAction` to configure the OkHttp client."
124+
)
80125
actual val logVerbosity: PNLogVerbosity
81126

82127
/**
@@ -103,7 +148,7 @@ actual interface PNConfiguration {
103148
val heartbeatInterval: Int
104149

105150
/**
106-
* The subscribe request timeout.
151+
* The subscribe read timeout.
107152
*
108153
* The value is in seconds.
109154
*
@@ -147,6 +192,9 @@ actual interface PNConfiguration {
147192
*
148193
* Defaults to 10.
149194
*/
195+
@Deprecated(
196+
message = "Use `subscribeOkHttpConfigureAction`, `nonSubscribeOkHttpConfigureAction`, or `filesOkHttpConfigureAction` to configure the OkHttp client."
197+
)
150198
val nonSubscribeReadTimeout: Int
151199

152200
/**
@@ -212,48 +260,75 @@ actual interface PNConfiguration {
212260
*
213261
* @see [Proxy]
214262
*/
263+
@Deprecated(
264+
message = "Use `subscribeOkHttpConfigureAction`, `nonSubscribeOkHttpConfigureAction`, or `filesOkHttpConfigureAction` to configure the OkHttp client."
265+
)
215266
val proxy: Proxy?
216267

217268
/**
218269
* @see [ProxySelector]
219270
*/
271+
@Deprecated(
272+
message = "Use `subscribeOkHttpConfigureAction`, `nonSubscribeOkHttpConfigureAction`, or `filesOkHttpConfigureAction` to configure the OkHttp client."
273+
)
220274
val proxySelector: ProxySelector?
221275

222276
/**
223277
* @see [Authenticator]
224278
*/
279+
@Deprecated(
280+
message = "Use `subscribeOkHttpConfigureAction`, `nonSubscribeOkHttpConfigureAction`, or `filesOkHttpConfigureAction` to configure the OkHttp client."
281+
)
225282
val proxyAuthenticator: Authenticator?
226283

227284
/**
228285
* @see [CertificatePinner]
229286
*/
287+
@Deprecated(
288+
message = "Use `subscribeOkHttpConfigureAction`, `nonSubscribeOkHttpConfigureAction`, or `filesOkHttpConfigureAction` to configure the OkHttp client."
289+
)
230290
val certificatePinner: CertificatePinner?
231291

232292
/**
233293
* Sets a custom [HttpLoggingInterceptor] for logging network traffic.
234294
*
235295
* @see [HttpLoggingInterceptor]
236296
*/
297+
@Deprecated(
298+
message = "Use `subscribeOkHttpConfigureAction`, `nonSubscribeOkHttpConfigureAction`, or `filesOkHttpConfigureAction` to configure the OkHttp client."
299+
)
237300
val httpLoggingInterceptor: HttpLoggingInterceptor?
238301

239302
/**
240303
* @see [SSLSocketFactory]
241304
*/
305+
@Deprecated(
306+
message = "Use `subscribeOkHttpConfigureAction`, `nonSubscribeOkHttpConfigureAction`, or `filesOkHttpConfigureAction` to configure the OkHttp client."
307+
)
242308
val sslSocketFactory: SSLSocketFactory?
243309

244310
/**
245311
* @see [X509ExtendedTrustManager]
246312
*/
313+
@Deprecated(
314+
message = "Use `subscribeOkHttpConfigureAction`, `nonSubscribeOkHttpConfigureAction`, or `filesOkHttpConfigureAction` to configure the OkHttp client."
315+
)
247316
val x509ExtendedTrustManager: X509ExtendedTrustManager?
248317

249318
/**
250319
* @see [okhttp3.ConnectionSpec]
251320
*/
321+
@Deprecated(
322+
message = "Use `subscribeOkHttpConfigureAction`, `nonSubscribeOkHttpConfigureAction`, or `filesOkHttpConfigureAction` to configure the OkHttp client."
323+
)
252324
val connectionSpec: ConnectionSpec?
253325

254326
/**
255327
* @see [javax.net.ssl.HostnameVerifier]
256328
*/
329+
@Deprecated(
330+
message = "Use `subscribeOkHttpConfigureAction`, `nonSubscribeOkHttpConfigureAction`, or `filesOkHttpConfigureAction` to configure the OkHttp client."
331+
)
257332
val hostnameVerifier: HostnameVerifier?
258333

259334
/**
@@ -505,6 +580,9 @@ actual interface PNConfiguration {
505580
/**
506581
* @see [okhttp3.Dispatcher.setMaxRequestsPerHost]
507582
*/
583+
@Deprecated(
584+
message = "Use `subscribeOkHttpConfigureAction`, `nonSubscribeOkHttpConfigureAction`, or `filesOkHttpConfigureAction` to configure the OkHttp client."
585+
)
508586
var maximumConnections: Int?
509587

510588
/**
@@ -594,6 +672,41 @@ actual interface PNConfiguration {
594672
*/
595673
var managePresenceListManually: Boolean
596674

675+
/**
676+
* The base [OkHttpClient] instance that will be used to preconfigure PubNub SDK's internal `OKHttpClients`.
677+
*/
678+
var baseOkHttpClient: OkHttpClient?
679+
680+
/**
681+
* Use this callback to configure any options on the [OkHttpClient] instance that will be used for Subscribe requests.
682+
*
683+
* Setting this option disables reading values from [logVerbosity], [httpLoggingInterceptor], [sslSocketFactory],
684+
* [connectionSpec], [hostnameVerifier], [proxy], [proxySelector], [proxyAuthenticator] and [certificatePinner] for
685+
* the instance of `OkHttpClient` servicing Subscribe requests. Those options should be set using the
686+
* [subscribeOkHttpConfigureAction] instead.
687+
*/
688+
var subscribeOkHttpConfigureAction: ((OkHttpClient.Builder) -> Unit)?
689+
690+
/**
691+
* Use this callback to configure any options on the [OkHttpClient] instance that will be used for requests other than Subscribe or File upload/download.
692+
*
693+
* Setting this option disables reading values from [logVerbosity], [httpLoggingInterceptor], [sslSocketFactory],
694+
* [connectionSpec], [hostnameVerifier], [proxy], [proxySelector], [proxyAuthenticator] and [certificatePinner] for
695+
* the instance of `OkHttpClient` servicing requests other than Subscribe and File upload/download. Those options
696+
* should be set using the [nonSubscribeOkHttpConfigureAction] instead.
697+
*/
698+
var nonSubscribeOkHttpConfigureAction: ((OkHttpClient.Builder) -> Unit)?
699+
700+
/**
701+
* Use this callback to configure any options on the [OkHttpClient] instance that will be used for File upload/download requests.
702+
*
703+
* Setting this option disables reading values from [logVerbosity], [httpLoggingInterceptor], [sslSocketFactory],
704+
* [connectionSpec], [hostnameVerifier], [proxy], [proxySelector], [proxyAuthenticator] and [certificatePinner] for
705+
* the instance of `OkHttpClient` servicing File upload/download requests. Those options
706+
* should be set using the [filesOkHttpConfigureAction] instead.
707+
*/
708+
var filesOkHttpConfigureAction: ((OkHttpClient.Builder) -> Unit)?
709+
597710
/**
598711
* Create a [PNConfiguration] object with values from this builder.
599712
*/
@@ -701,6 +814,36 @@ interface PNConfigurationOverride {
701814
*/
702815
var nonSubscribeReadTimeout: Int
703816

817+
/**
818+
* Use this callback to configure any options on the [OkHttpClient] instance that will be used for Subscribe requests.
819+
*
820+
* Setting this option disables reading values from [logVerbosity], [httpLoggingInterceptor], [sslSocketFactory],
821+
* [connectionSpec], [hostnameVerifier], [proxy], [proxySelector], [proxyAuthenticator] and [certificatePinner] for
822+
* the instance of `OkHttpClient` servicing Subscribe requests. Those options should be set using the
823+
* [subscribeOkHttpConfigureAction] instead.
824+
*/
825+
var subscribeOkHttpConfigureAction: ((OkHttpClient.Builder) -> Unit)?
826+
827+
/**
828+
* Use this callback to configure any options on the [OkHttpClient] instance that will be used for requests other than Subscribe or File upload/download.
829+
*
830+
* Setting this option disables reading values from [logVerbosity], [httpLoggingInterceptor], [sslSocketFactory],
831+
* [connectionSpec], [hostnameVerifier], [proxy], [proxySelector], [proxyAuthenticator] and [certificatePinner] for
832+
* the instance of `OkHttpClient` servicing requests other than Subscribe and File upload/download. Those options
833+
* should be set using the [nonSubscribeOkHttpConfigureAction] instead.
834+
*/
835+
var nonSubscribeOkHttpConfigureAction: ((OkHttpClient.Builder) -> Unit)?
836+
837+
/**
838+
* Use this callback to configure any options on the [OkHttpClient] instance that will be used for File upload/download requests.
839+
*
840+
* Setting this option disables reading values from [logVerbosity], [httpLoggingInterceptor], [sslSocketFactory],
841+
* [connectionSpec], [hostnameVerifier], [proxy], [proxySelector], [proxyAuthenticator] and [certificatePinner] for
842+
* the instance of `OkHttpClient` servicing File upload/download requests. Those options
843+
* should be set using the [filesOkHttpConfigureAction] instead.
844+
*/
845+
var filesOkHttpConfigureAction: ((OkHttpClient.Builder) -> Unit)?
846+
704847
/**
705848
* Create a [PNConfiguration] object with values from this builder.
706849
*/

0 commit comments

Comments
 (0)