Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
1a53ca74
Unverified
Commit
1a53ca74
authored
Apr 15, 2019
by
Tim Neutkens
Committed by
GitHub
Apr 15, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add x-powered-by (#7029)
* Add x-powered-by * Remove ampEnabled type
parent
e4ceb903
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
27 additions
and
8 deletions
+27
-8
index.ts
examples/custom-server-typescript/server/index.ts
+1
-3
config.js
packages/next-server/server/config.js
+1
-0
next-server.ts
packages/next-server/server/next-server.ts
+4
-4
send-html.ts
packages/next-server/server/send-html.ts
+5
-1
next.config.js
test/integration/config/next.config.js
+1
-0
index.test.js
test/integration/config/test/index.test.js
+8
-0
index.test.js
test/integration/production/test/index.test.js
+7
-0
No files found.
examples/custom-server-typescript/server/index.ts
View file @
1a53ca74
...
...
@@ -21,7 +21,5 @@ app.prepare()
handle
(
req
,
res
,
parsedUrl
)
}
})
.
listen
(
port
,
()
=>
{
console
.
log
(
`> Ready on http://localhost:
${
port
}
`
)
})
.
listen
(
port
)
})
packages/next-server/server/config.js
View file @
1a53ca74
...
...
@@ -16,6 +16,7 @@ const defaultConfig = {
generateEtags
:
true
,
pageExtensions
:
[
'jsx'
,
'js'
],
target
:
'server'
,
poweredByHeader
:
true
,
onDemandEntries
:
{
maxInactiveAge
:
60
*
1000
,
pagesBufferLength
:
2
...
...
packages/next-server/server/next-server.ts
View file @
1a53ca74
...
...
@@ -28,8 +28,6 @@ type ServerConstructor = {
conf
?:
NextConfig
,
}
const
ENDING_IN_JSON_REGEX
=
/
\.
json$/
export
default
class
Server
{
dir
:
string
quiet
:
boolean
...
...
@@ -37,6 +35,7 @@ export default class Server {
distDir
:
string
buildId
:
string
renderOpts
:
{
poweredByHeader
:
boolean
noDirtyAmp
:
boolean
ampBindInitData
:
boolean
staticMarkup
:
boolean
...
...
@@ -78,6 +77,7 @@ export default class Server {
this
.
renderOpts
=
{
noDirtyAmp
:
this
.
nextConfig
.
experimental
.
noDirtyAmp
,
ampBindInitData
:
this
.
nextConfig
.
experimental
.
ampBindInitData
,
poweredByHeader
:
this
.
nextConfig
.
poweredByHeader
,
staticMarkup
,
buildId
:
this
.
buildId
,
generateEtags
,
...
...
@@ -248,8 +248,8 @@ export default class Server {
res
:
ServerResponse
,
html
:
string
,
)
{
const
{
generateEtags
}
=
this
.
renderOpts
return
sendHTML
(
req
,
res
,
html
,
{
generateEtags
})
const
{
generateEtags
,
poweredByHeader
}
=
this
.
renderOpts
return
sendHTML
(
req
,
res
,
html
,
{
generateEtags
,
poweredByHeader
})
}
public
async
render
(
...
...
packages/next-server/server/send-html.ts
View file @
1a53ca74
...
...
@@ -3,10 +3,14 @@ import generateETag from 'etag'
import
fresh
from
'fresh'
import
{
isResSent
}
from
'../lib/utils'
export
function
sendHTML
(
req
:
IncomingMessage
,
res
:
ServerResponse
,
html
:
string
,
{
generateEtags
}:
{
generateEtags
:
boolean
})
{
export
function
sendHTML
(
req
:
IncomingMessage
,
res
:
ServerResponse
,
html
:
string
,
{
generateEtags
,
poweredByHeader
}:
{
generateEtags
:
boolean
,
poweredByHeader
:
boolean
})
{
if
(
isResSent
(
res
))
return
const
etag
=
generateEtags
?
generateETag
(
html
)
:
undefined
if
(
poweredByHeader
)
{
res
.
setHeader
(
'X-Powered-By'
,
'Next.js'
)
}
if
(
fresh
(
req
.
headers
,
{
etag
}))
{
res
.
statusCode
=
304
res
.
end
()
...
...
test/integration/config/next.config.js
View file @
1a53ca74
...
...
@@ -7,6 +7,7 @@ module.exports = withCSS(withSass({
// Make sure entries are not getting disposed.
maxInactiveAge
:
1000
*
60
*
60
},
poweredByHeader
:
false
,
cssModules
:
true
,
serverRuntimeConfig
:
{
mySecret
:
'secret'
...
...
test/integration/config/test/index.test.js
View file @
1a53ca74
...
...
@@ -8,6 +8,7 @@ import {
launchApp
,
killApp
}
from
'next-test-utils'
import
fetch
from
'node-fetch'
// test suits
import
rendering
from
'./rendering'
...
...
@@ -29,6 +30,13 @@ describe('Configuration', () => {
renderViaHTTP
(
context
.
appPort
,
'/module-only-component'
)
])
})
it
(
'should disable X-Powered-By header support'
,
async
()
=>
{
const
url
=
`http://localhost:
${
context
.
appPort
}
/`
const
header
=
(
await
fetch
(
url
)).
headers
.
get
(
'X-Powered-By'
)
expect
(
header
).
not
.
toBe
(
'Next.js'
)
})
afterAll
(()
=>
{
killApp
(
context
.
server
)
})
...
...
test/integration/production/test/index.test.js
View file @
1a53ca74
...
...
@@ -55,6 +55,13 @@ describe('Production Usage', () => {
expect
(
res2
.
status
).
toBe
(
304
)
})
it
(
'should have X-Powered-By header support'
,
async
()
=>
{
const
url
=
`http://localhost:
${
appPort
}
/`
const
header
=
(
await
fetch
(
url
)).
headers
.
get
(
'X-Powered-By'
)
expect
(
header
).
toBe
(
'Next.js'
)
})
it
(
'should render 404 for routes that do not exist'
,
async
()
=>
{
const
url
=
`http://localhost:
${
appPort
}
/abcdefghijklmno`
const
res
=
await
fetch
(
url
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment