@@ -106,7 +106,8 @@ export class FunctionsService implements _FirebaseService {
106
106
authProvider : Provider < FirebaseAuthInternalName > ,
107
107
messagingProvider : Provider < MessagingInternalComponentName > ,
108
108
appCheckProvider : Provider < AppCheckInternalComponentName > ,
109
- regionOrCustomDomain : string = DEFAULT_REGION
109
+ regionOrCustomDomain : string = DEFAULT_REGION ,
110
+ readonly fetchImpl : typeof fetch = fetch ,
110
111
) {
111
112
this . contextProvider = new ContextProvider (
112
113
authProvider ,
@@ -224,13 +225,14 @@ export function httpsCallableFromURL<RequestData, ResponseData, StreamData = unk
224
225
async function postJSON (
225
226
url : string ,
226
227
body : unknown ,
227
- headers : { [ key : string ] : string }
228
+ headers : { [ key : string ] : string } ,
229
+ fetchImpl : typeof fetch
228
230
) : Promise < HttpResponse > {
229
231
headers [ 'Content-Type' ] = 'application/json' ;
230
232
231
233
let response : Response ;
232
234
try {
233
- response = await fetch ( url , {
235
+ response = await fetchImpl ( url , {
234
236
method : 'POST' ,
235
237
body : JSON . stringify ( body ) ,
236
238
headers
@@ -308,7 +310,7 @@ async function callAtURL(
308
310
309
311
const failAfterHandle = failAfter ( timeout ) ;
310
312
const response = await Promise . race ( [
311
- postJSON ( url , body , headers ) ,
313
+ postJSON ( url , body , headers , functionsInstance . fetchImpl ) ,
312
314
failAfterHandle . promise ,
313
315
functionsInstance . cancelAllRequests
314
316
] ) ;
@@ -364,7 +366,7 @@ function stream(
364
366
options ?: HttpsCallableStreamOptions
365
367
) : Promise < HttpsCallableStreamResult > {
366
368
const url = functionsInstance . _url ( name ) ;
367
- return streamAtURL ( functionsInstance , url , options ) ;
369
+ return streamAtURL ( functionsInstance , url , data , options ) ;
368
370
}
369
371
370
372
/**
@@ -401,7 +403,7 @@ async function streamAtURL(
401
403
402
404
let response : Response ;
403
405
try {
404
- response = await fetch ( url , {
406
+ response = await functionsInstance . fetchImpl ( url , {
405
407
method : 'POST' ,
406
408
body : JSON . stringify ( body ) ,
407
409
headers,
@@ -458,7 +460,6 @@ async function streamAtURL(
458
460
resultRejecter = reject ;
459
461
} ) ;
460
462
461
- // Set up abort handler for the stream
462
463
options ?. signal ?. addEventListener ( 'abort' , ( ) => {
463
464
reader . cancel ( ) ;
464
465
const error = new FunctionsError (
0 commit comments