Commit dbd41725 authored by Luis Fernando Alvarez D's avatar Luis Fernando Alvarez D Committed by Tim Neutkens

Removed the X-Powered-By header (#6789)

Related to #6776 
parent affe356a
...@@ -8,7 +8,6 @@ const defaultConfig = { ...@@ -8,7 +8,6 @@ const defaultConfig = {
env: [], env: [],
webpack: null, webpack: null,
webpackDevMiddleware: null, webpackDevMiddleware: null,
poweredByHeader: true,
distDir: '.next', distDir: '.next',
assetPrefix: '', assetPrefix: '',
configOrigin: 'default', configOrigin: 'default',
......
...@@ -272,9 +272,6 @@ export default class Server { ...@@ -272,9 +272,6 @@ export default class Server {
return return
} }
if (this.nextConfig.poweredByHeader) {
res.setHeader('X-Powered-By', 'Next.js ' + process.env.__NEXT_VERSION)
}
return this.sendHTML(req, res, html) return this.sendHTML(req, res, html)
} }
......
...@@ -1450,17 +1450,6 @@ module.exports = { ...@@ -1450,17 +1450,6 @@ module.exports = {
} }
``` ```
#### Disabling X-Powered-By
Next.js generates X-Powered-By response header with version information for every page. You can disable it with:
```js
// next.config.js
module.exports = {
poweredByHeader: false
}
```
#### Configuring the onDemandEntries #### Configuring the onDemandEntries
Next exposes some options that give you some control over how the server will dispose or keep in memories pages built: Next exposes some options that give you some control over how the server will dispose or keep in memories pages built:
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
import { readFileSync } from 'fs' import { readFileSync } from 'fs'
import { join } from 'path' import { join } from 'path'
import { import {
pkg,
nextServer, nextServer,
runNextCommand, runNextCommand,
startApp, startApp,
...@@ -310,45 +309,6 @@ describe('Production Usage', () => { ...@@ -310,45 +309,6 @@ describe('Production Usage', () => {
}) })
}) })
describe('X-Powered-By header', () => {
it('should set it by default', async () => {
const req = { url: '/stateless', headers: {} }
const headers = {}
const res = {
getHeader (key) {
return headers[key]
},
setHeader (key, value) {
headers[key] = value
},
end () {}
}
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.nextConfig.poweredByHeader
app.nextConfig.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.nextConfig.poweredByHeader = originalConfigValue
})
})
it('should not expose the compiled page file in development', async () => { it('should not expose the compiled page file in development', async () => {
const url = `http://localhost:${appPort}` const url = `http://localhost:${appPort}`
await fetch(`${url}/stateless`) // make sure the stateless page is built await fetch(`${url}/stateless`) // make sure the stateless page is built
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment