diff --git a/errors/powered-by-header-option-removed.md b/errors/powered-by-header-option-removed.md deleted file mode 100644 index 216fbda8..00000000 --- a/errors/powered-by-header-option-removed.md +++ /dev/null @@ -1,15 +0,0 @@ -# The poweredByHeader has been removed - -#### Why This Error Occurred - -Starting at Next.js version 5.0.0 the `poweredByHeader` option has been removed. - -#### Possible Ways to Fix It - -If you still want to remove `x-powered-by` you can use one of the custom-server examples. - -And then manually remove the header using `res.removeHeader('x-powered-by')` - -### Useful Links - -- [Custom Server documentation + examples](https://github.com/zeit/next.js#custom-server-and-routing) diff --git a/server/config.js b/server/config.js index 4ea6bc23..7ed863c0 100644 --- a/server/config.js +++ b/server/config.js @@ -5,6 +5,7 @@ const cache = new Map() const defaultConfig = { webpack: null, webpackDevMiddleware: null, + poweredByHeader: true, distDir: '.next', assetPrefix: '', configOrigin: 'default', @@ -33,9 +34,6 @@ function loadConfig (dir, customConfig) { if (path && path.length) { const userConfigModule = require(path) userConfig = userConfigModule.default || userConfigModule - if (userConfig.poweredByHeader === true || userConfig.poweredByHeader === false) { - console.warn('> the `poweredByHeader` option has been removed https://err.sh/zeit/next.js/powered-by-header-option-removed') - } userConfig.configOrigin = 'next.config.js' } diff --git a/server/index.js b/server/index.js index 9fe619b9..1b1e546b 100644 --- a/server/index.js +++ b/server/index.js @@ -323,7 +323,9 @@ export default class Server { return } - res.setHeader('X-Powered-By', `Next.js ${pkg.version}`) + if (this.config.poweredByHeader) { + res.setHeader('X-Powered-By', `Next.js ${pkg.version}`) + } return sendHTML(req, res, html, req.method, this.renderOpts) } diff --git a/test/integration/production/test/index.test.js b/test/integration/production/test/index.test.js index ac58096d..47da09c8 100644 --- a/test/integration/production/test/index.test.js +++ b/test/integration/production/test/index.test.js @@ -134,6 +134,26 @@ describe('Production Usage', () => { await app.render(req, res, req.url) expect(headers['X-Powered-By']).toEqual(`Next.js ${pkg.version}`) }) + + it('should not set it when poweredByHeader==false', async () => { + const req = { url: '/stateless', headers: {} } + const originalConfigValue = app.config.poweredByHeader + app.config.poweredByHeader = false + const res = { + getHeader () { + return false + }, + setHeader (key, value) { + if (key === 'XPoweredBy') { + throw new Error('Should not set the XPoweredBy header') + } + }, + end () {} + } + + await app.render(req, res, req.url) + app.config.poweredByHeader = originalConfigValue + }) }) dynamicImportTests(context, (p, q) => renderViaHTTP(context.appPort, p, q))