Skip to content

Commit cc870b1

Browse files
committed
Enable setting OkHttpClient for FirebaseFunctions
1 parent fef7bad commit cc870b1

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import org.junit.Test;
2525
import org.junit.runner.RunWith;
2626

27+
import okhttp3.OkHttpClient;
28+
2729
@RunWith(AndroidJUnit4.class)
2830
public class FirebaseFunctionsTest {
2931

@@ -101,6 +103,17 @@ public void testEmulatorSettings() {
101103
assertEquals(functions1.getURL("foo").toString(), functions2.getURL("foo").toString());
102104
}
103105

106+
@Test
107+
public void testSetOkHttpClient() {
108+
OkHttpClient client = new OkHttpClient.Builder().build();
109+
FirebaseApp app = getApp("testSetOkHttpClient");
110+
FirebaseFunctions functions = FirebaseFunctions.getInstance(app);
111+
112+
functions.setOkHttpClient(client);
113+
114+
assertEquals(client, functions.getOkHttpClient());
115+
}
116+
104117
private FirebaseApp getApp(String name) {
105118
return FirebaseApp.initializeApp(
106119
InstrumentationRegistry.getInstrumentation().getTargetContext(),

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public class FirebaseFunctions {
6363
private static boolean providerInstallStarted = false;
6464

6565
// The network client to use for HTTPS requests.
66-
private final OkHttpClient client;
66+
private OkHttpClient client;
6767

6868
// A serializer to encode/decode parameters and return values.
6969
private final Serializer serializer;
@@ -277,6 +277,19 @@ public void useEmulator(@NonNull String host, int port) {
277277
this.emulatorSettings = new EmulatedServiceSettings(host, port);
278278
}
279279

280+
/**
281+
* Sets the OkHttpClient instance used by this FirebaseFunctions instance.
282+
*
283+
* @param client The OkHttpClient instance
284+
*/
285+
public void setOkHttpClient(OkHttpClient client) {
286+
this.client = client;
287+
}
288+
289+
OkHttpClient getOkHttpClient() {
290+
return this.client;
291+
}
292+
280293
/**
281294
* Calls a Callable HTTPS trigger endpoint.
282295
*

0 commit comments

Comments
 (0)