Skip to content

Commit 33435b5

Browse files
Laurent Pellegrinolaurenzlong
authored andcommitted
Pass the raw Express request to CallableContext (#269)
1 parent 6f1bc88 commit 33435b5

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

spec/providers/https.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,24 @@ describe('callable.FunctionBuilder', () => {
443443
},
444444
});
445445
});
446+
447+
it('should expose raw request', async () => {
448+
const mockRequest = request(null, 'application/json', {});
449+
await runTest({
450+
httpRequest: mockRequest,
451+
expectedData: null,
452+
callableFunction: (data, context) => {
453+
expect(context.rawRequest).to.not.be.undefined;
454+
expect(context.rawRequest).to.equal(mockRequest);
455+
return null;
456+
},
457+
expectedHttpResponse: {
458+
status: 200,
459+
headers: expectedResponseHeaders,
460+
body: {result: null},
461+
},
462+
});
463+
});
446464
});
447465
});
448466

src/providers/https.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,11 @@ export interface CallableContext {
217217
* An unverified token for a Firebase Instance ID.
218218
*/
219219
instanceIdToken?: string;
220+
221+
/**
222+
* The raw request handled by the callable.
223+
*/
224+
rawRequest: express.Request;
220225
}
221226

222227
// The allowed interface for an http request for a callable function.
@@ -373,7 +378,7 @@ export function onCall(
373378
throw new HttpsError('invalid-argument', 'Bad Request');
374379
}
375380

376-
const context: CallableContext = {};
381+
const context: CallableContext = { rawRequest: req };
377382

378383
const authorization = req.header('Authorization');
379384
if (authorization) {

0 commit comments

Comments
 (0)