Skip to content

Commit ab99970

Browse files
committed
Re-introduce fetchImpl.
1 parent d28863c commit ab99970

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

packages/functions/src/service.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ export class FunctionsService implements _FirebaseService {
106106
authProvider: Provider<FirebaseAuthInternalName>,
107107
messagingProvider: Provider<MessagingInternalComponentName>,
108108
appCheckProvider: Provider<AppCheckInternalComponentName>,
109-
regionOrCustomDomain: string = DEFAULT_REGION
109+
regionOrCustomDomain: string = DEFAULT_REGION,
110+
readonly fetchImpl: typeof fetch = fetch,
110111
) {
111112
this.contextProvider = new ContextProvider(
112113
authProvider,
@@ -224,13 +225,14 @@ export function httpsCallableFromURL<RequestData, ResponseData, StreamData = unk
224225
async function postJSON(
225226
url: string,
226227
body: unknown,
227-
headers: { [key: string]: string }
228+
headers: { [key: string]: string },
229+
fetchImpl: typeof fetch
228230
): Promise<HttpResponse> {
229231
headers['Content-Type'] = 'application/json';
230232

231233
let response: Response;
232234
try {
233-
response = await fetch(url, {
235+
response = await fetchImpl(url, {
234236
method: 'POST',
235237
body: JSON.stringify(body),
236238
headers
@@ -308,7 +310,7 @@ async function callAtURL(
308310

309311
const failAfterHandle = failAfter(timeout);
310312
const response = await Promise.race([
311-
postJSON(url, body, headers),
313+
postJSON(url, body, headers, functionsInstance.fetchImpl),
312314
failAfterHandle.promise,
313315
functionsInstance.cancelAllRequests
314316
]);
@@ -364,7 +366,7 @@ function stream(
364366
options?: HttpsCallableStreamOptions
365367
): Promise<HttpsCallableStreamResult> {
366368
const url = functionsInstance._url(name);
367-
return streamAtURL(functionsInstance, url, options);
369+
return streamAtURL(functionsInstance, url, data, options);
368370
}
369371

370372
/**
@@ -401,7 +403,7 @@ async function streamAtURL(
401403

402404
let response: Response;
403405
try {
404-
response = await fetch(url, {
406+
response = await functionsInstance.fetchImpl(url, {
405407
method: 'POST',
406408
body: JSON.stringify(body),
407409
headers,
@@ -458,7 +460,6 @@ async function streamAtURL(
458460
resultRejecter = reject;
459461
});
460462

461-
// Set up abort handler for the stream
462463
options?.signal?.addEventListener('abort', () => {
463464
reader.cancel();
464465
const error = new FunctionsError(

0 commit comments

Comments
 (0)