Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions spec/providers/https.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,27 @@ describe('callable.FunctionBuilder', () => {
},
});
});

it('should handle headers', async () => {
const mockRequest = request(null, 'application/json', {});
await runTest({
httpRequest: mockRequest,
expectedData: null,
callableFunction: (data, context) => {
expect(context.auth).to.be.undefined;
expect(context.headers).to.not.be.undefined;
expect(context.headers).to.equal(mockRequest.headers);
expect(context.instanceIdToken).to.be.undefined;
return null;
},
expectedHttpResponse: {
status: 200,
headers: expectedResponseHeaders,
body: {result: null},
},
});
});

});
});

Expand Down
8 changes: 7 additions & 1 deletion src/providers/https.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import * as firebase from 'firebase-admin';
import { apps } from '../apps';
import * as _ from 'lodash';
import * as cors from 'cors';
import {IncomingHttpHeaders} from 'http';

export function onRequest(handler: (req: express.Request, resp: express.Response) => void): HttpsFunction {
// lets us add __trigger without altering handler:
Expand Down Expand Up @@ -213,6 +214,11 @@ export interface CallableContext {
token: firebase.auth.DecodedIdToken;
};

/**
* Incoming headers.
*/
headers: IncomingHttpHeaders;

/**
* An unverified token for a Firebase Instance ID.
*/
Expand Down Expand Up @@ -373,7 +379,7 @@ export function onCall(
throw new HttpsError('invalid-argument', 'Bad Request');
}

const context: CallableContext = {};
const context: CallableContext = { headers: req.headers };

const authorization = req.header('Authorization');
if (authorization) {
Expand Down