Skip to content

Unable to remove the X-Powered-By header when using onRequest() #754

@SDrinkwater

Description

@SDrinkwater

Related issues

[REQUIRED] Version info

node: 10.20.1

firebase-functions: 3.9.0

firebase-tools: 8.4.2

firebase-admin: 9.0.0

[REQUIRED] Test case

Deploy the following function, or run it locally with the firebase emulator:

import * as express from 'express';
import { https } from 'firebase-functions';

const app = express();
app.disable('x-powered-by');

app.get('/test', (_req, res) => {
  res.status(200).end();
});

export const api = https.onRequest(app);

[REQUIRED] Steps to reproduce

Run the following command in your terminal (update the url to match the project - this example is using the base emulator url):

curl -i http://localhost:5001/{project-name/hosting-location}/api/test

Notice that the x-powered-by header comes back populated with Express.

[REQUIRED] Expected behavior

I would expect to have full control over which headers are returned with the response when using https.onRequest(). Regardless of which approach I use, this header always gets populated.

I have tried the following approaches:

app.disable('x-powered-by')
app.use(function (req, res, next) {  
  res.removeHeader("x-powered-by");
  next();
});
app.set('x-powered-by', false);  

[REQUIRED] Actual behavior

The x-powered-by header always gets populated with Express.

Were you able to successfully deploy your functions?

Yes, everything deploys successfully with no errors.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions