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
1424b84c
Unverified
Commit
1424b84c
authored
Nov 05, 2017
by
Tim Neutkens
Committed by
GitHub
Nov 05, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow overriding Content-Type (#3242)
* Allow overriding Content-Type * Mock getHeader
parent
828dac7d
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
43 additions
and
7 deletions
+43
-7
render.js
server/render.js
+3
-1
custom-encoding.js
test/integration/basic/pages/custom-encoding.js
+13
-0
index.test.js
test/integration/basic/test/index.test.js
+2
-1
rendering.js
test/integration/basic/test/rendering.js
+11
-1
index.test.js
test/integration/production/test/index.test.js
+6
-0
next-test-utils.js
test/lib/next-test-utils.js
+5
-1
yarn.lock
yarn.lock
+3
-3
No files found.
server/render.js
View file @
1424b84c
...
@@ -185,7 +185,9 @@ export function sendHTML (req, res, html, method, { dev }) {
...
@@ -185,7 +185,9 @@ export function sendHTML (req, res, html, method, { dev }) {
}
}
res
.
setHeader
(
'ETag'
,
etag
)
res
.
setHeader
(
'ETag'
,
etag
)
res
.
setHeader
(
'Content-Type'
,
'text/html'
)
if
(
!
res
.
getHeader
(
'Content-Type'
))
{
res
.
setHeader
(
'Content-Type'
,
'text/html'
)
}
res
.
setHeader
(
'Content-Length'
,
Buffer
.
byteLength
(
html
))
res
.
setHeader
(
'Content-Length'
,
Buffer
.
byteLength
(
html
))
res
.
end
(
method
===
'HEAD'
?
null
:
html
)
res
.
end
(
method
===
'HEAD'
?
null
:
html
)
}
}
...
...
test/integration/basic/pages/custom-encoding.js
0 → 100644
View file @
1424b84c
import
React
from
'react'
export
default
class
extends
React
.
Component
{
static
async
getInitialProps
({
res
})
{
if
(
res
)
{
res
.
setHeader
(
'Content-Type'
,
'text/html; charset=utf-8'
)
}
return
{}
}
render
()
{
return
null
}
}
test/integration/basic/test/index.test.js
View file @
1424b84c
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
import
{
join
}
from
'path'
import
{
join
}
from
'path'
import
{
import
{
renderViaHTTP
,
renderViaHTTP
,
fetchViaHTTP
,
findPort
,
findPort
,
launchApp
,
launchApp
,
killApp
killApp
...
@@ -55,7 +56,7 @@ describe('Basic Features', () => {
...
@@ -55,7 +56,7 @@ describe('Basic Features', () => {
})
})
afterAll
(()
=>
killApp
(
context
.
server
))
afterAll
(()
=>
killApp
(
context
.
server
))
rendering
(
context
,
'Rendering via HTTP'
,
(
p
,
q
)
=>
renderViaHTTP
(
context
.
appPort
,
p
,
q
))
rendering
(
context
,
'Rendering via HTTP'
,
(
p
,
q
)
=>
renderViaHTTP
(
context
.
appPort
,
p
,
q
)
,
(
p
,
q
)
=>
fetchViaHTTP
(
context
.
appPort
,
p
,
q
)
)
clientNavigation
(
context
,
(
p
,
q
)
=>
renderViaHTTP
(
context
.
appPort
,
p
,
q
))
clientNavigation
(
context
,
(
p
,
q
)
=>
renderViaHTTP
(
context
.
appPort
,
p
,
q
))
dynamic
(
context
,
(
p
,
q
)
=>
renderViaHTTP
(
context
.
appPort
,
p
,
q
))
dynamic
(
context
,
(
p
,
q
)
=>
renderViaHTTP
(
context
.
appPort
,
p
,
q
))
hmr
(
context
,
(
p
,
q
)
=>
renderViaHTTP
(
context
.
appPort
,
p
,
q
))
hmr
(
context
,
(
p
,
q
)
=>
renderViaHTTP
(
context
.
appPort
,
p
,
q
))
...
...
test/integration/basic/test/rendering.js
View file @
1424b84c
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
import
cheerio
from
'cheerio'
import
cheerio
from
'cheerio'
export
default
function
({
app
},
suiteName
,
render
)
{
export
default
function
({
app
},
suiteName
,
render
,
fetch
)
{
async
function
get
$
(
path
,
query
)
{
async
function
get
$
(
path
,
query
)
{
const
html
=
await
render
(
path
,
query
)
const
html
=
await
render
(
path
,
query
)
return
cheerio
.
load
(
html
)
return
cheerio
.
load
(
html
)
...
@@ -63,6 +63,16 @@ export default function ({ app }, suiteName, render) {
...
@@ -63,6 +63,16 @@ export default function ({ app }, suiteName, render) {
expect
(
$
(
'pre'
).
text
().
includes
(
expectedErrorMessage
)).
toBeTruthy
()
expect
(
$
(
'pre'
).
text
().
includes
(
expectedErrorMessage
)).
toBeTruthy
()
})
})
test
(
'default Content-Type'
,
async
()
=>
{
const
res
=
await
fetch
(
'/stateless'
)
expect
(
res
.
headers
.
get
(
'Content-Type'
)).
toMatch
(
'text/html'
)
})
test
(
'setting Content-Type in getInitialProps'
,
async
()
=>
{
const
res
=
await
fetch
(
'/custom-encoding'
)
expect
(
res
.
headers
.
get
(
'Content-Type'
)).
toMatch
(
'text/html; charset=utf-8'
)
})
test
(
'allows to import .json files'
,
async
()
=>
{
test
(
'allows to import .json files'
,
async
()
=>
{
const
html
=
await
render
(
'/json'
)
const
html
=
await
render
(
'/json'
)
expect
(
html
.
includes
(
'Zeit'
)).
toBeTruthy
()
expect
(
html
.
includes
(
'Zeit'
)).
toBeTruthy
()
...
...
test/integration/production/test/index.test.js
View file @
1424b84c
...
@@ -117,6 +117,9 @@ describe('Production Usage', () => {
...
@@ -117,6 +117,9 @@ describe('Production Usage', () => {
const
req
=
{
url
:
'/stateless'
,
headers
:
{}
}
const
req
=
{
url
:
'/stateless'
,
headers
:
{}
}
const
headers
=
{}
const
headers
=
{}
const
res
=
{
const
res
=
{
getHeader
(
key
)
{
return
headers
[
key
]
},
setHeader
(
key
,
value
)
{
setHeader
(
key
,
value
)
{
headers
[
key
]
=
value
headers
[
key
]
=
value
},
},
...
@@ -132,6 +135,9 @@ describe('Production Usage', () => {
...
@@ -132,6 +135,9 @@ describe('Production Usage', () => {
const
originalConfigValue
=
app
.
config
.
poweredByHeader
const
originalConfigValue
=
app
.
config
.
poweredByHeader
app
.
config
.
poweredByHeader
=
false
app
.
config
.
poweredByHeader
=
false
const
res
=
{
const
res
=
{
getHeader
()
{
return
false
},
setHeader
(
key
,
value
)
{
setHeader
(
key
,
value
)
{
if
(
key
===
'X-Powered-By'
)
{
if
(
key
===
'X-Powered-By'
)
{
throw
new
Error
(
'Should not set the X-Powered-By header'
)
throw
new
Error
(
'Should not set the X-Powered-By header'
)
...
...
test/lib/next-test-utils.js
View file @
1424b84c
...
@@ -23,8 +23,12 @@ export function renderViaAPI (app, pathname, query) {
...
@@ -23,8 +23,12 @@ export function renderViaAPI (app, pathname, query) {
}
}
export
function
renderViaHTTP
(
appPort
,
pathname
,
query
)
{
export
function
renderViaHTTP
(
appPort
,
pathname
,
query
)
{
return
fetchViaHTTP
(
appPort
,
pathname
,
query
).
then
((
res
)
=>
res
.
text
())
}
export
function
fetchViaHTTP
(
appPort
,
pathname
,
query
)
{
const
url
=
`http://localhost:
${
appPort
}${
pathname
}${
query
?
`?
${
qs
.
stringify
(
query
)}
`
:
''
}
`
const
url
=
`http://localhost:
${
appPort
}${
pathname
}${
query
?
`?
${
qs
.
stringify
(
query
)}
`
:
''
}
`
return
fetch
(
url
)
.
then
((
res
)
=>
res
.
text
())
return
fetch
(
url
)
}
}
export
function
findPort
()
{
export
function
findPort
()
{
...
...
yarn.lock
View file @
1424b84c
...
@@ -6071,9 +6071,9 @@ strip-json-comments@~2.0.1:
...
@@ -6071,9 +6071,9 @@ strip-json-comments@~2.0.1:
version "2.0.1"
version "2.0.1"
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a"
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a"
styled-jsx@2.1.
1
:
styled-jsx@2.1.
2
:
version "2.1.
1
"
version "2.1.
2
"
resolved "https://registry.yarnpkg.com/styled-jsx/-/styled-jsx-2.1.
1.tgz#e7481c7554df50d605cdc84a4e53c58fec3449b5
"
resolved "https://registry.yarnpkg.com/styled-jsx/-/styled-jsx-2.1.
2.tgz#c84823402678022355b090d98d959ba126b97911
"
dependencies:
dependencies:
babel-plugin-syntax-jsx "6.18.0"
babel-plugin-syntax-jsx "6.18.0"
babel-types "6.23.0"
babel-types "6.23.0"
...
...
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