Skip to content

Commit 7ff13c5

Browse files
committed
Enable setting OkHttpClient for FirebaseFunctions
1 parent 7b828fc commit 7ff13c5

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

firebase-functions/src/androidTest/java/com/google/firebase/functions/FirebaseFunctionsTest.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import com.google.firebase.FirebaseApp
1919
import com.google.firebase.FirebaseOptions
2020
import com.google.firebase.functions.FirebaseFunctions.Companion.getInstance
2121
import junit.framework.TestCase.assertEquals
22+
import okhttp3.OkHttpClient
2223
import org.junit.Assert
2324
import org.junit.Test
2425
import org.junit.runner.RunWith
@@ -91,6 +92,17 @@ class FirebaseFunctionsTest {
9192
assertEquals(functions1.getURL("foo").toString(), functions2.getURL("foo").toString())
9293
}
9394

95+
@Test
96+
fun testSetOkHttpClient() {
97+
val client = OkHttpClient.Builder().build()
98+
val app = getApp("testSetOkHttpClient")
99+
val functions = getInstance(app)
100+
101+
functions.setOkHttpClient(client)
102+
103+
assertEquals(client, functions.getOkHttpClient())
104+
}
105+
94106
private fun getApp(name: String): FirebaseApp {
95107
return FirebaseApp.initializeApp(
96108
InstrumentationRegistry.getInstrumentation().targetContext,

firebase-functions/src/main/java/com/google/firebase/functions/FirebaseFunctions.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ internal constructor(
5858
@UiThread uiExecutor: Executor
5959
) {
6060
// The network client to use for HTTPS requests.
61-
private val client: OkHttpClient = OkHttpClient()
61+
private var client: OkHttpClient = OkHttpClient()
6262

6363
// A serializer to encode/decode parameters and return values.
6464
private val serializer: Serializer = Serializer()
@@ -311,6 +311,12 @@ internal constructor(
311311
return tcs.task
312312
}
313313

314+
public fun setOkHttpClient(client: OkHttpClient) {
315+
this.client = client
316+
}
317+
318+
public fun getOkHttpClient(): OkHttpClient = this.client
319+
314320
public companion object {
315321
/** A task that will be resolved once ProviderInstaller has installed what it needs to. */
316322
private val providerInstalled = TaskCompletionSource<Void>()

0 commit comments

Comments
 (0)