mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Add a charset to the default Content-Type (#3333)
This commit is contained in:
parent
e2bcb039cf
commit
732696e840
|
@ -186,7 +186,7 @@ export function sendHTML (req, res, html, method, { dev }) {
|
|||
|
||||
res.setHeader('ETag', etag)
|
||||
if (!res.getHeader('Content-Type')) {
|
||||
res.setHeader('Content-Type', 'text/html')
|
||||
res.setHeader('Content-Type', 'text/html; charset=utf-8')
|
||||
}
|
||||
res.setHeader('Content-Length', Buffer.byteLength(html))
|
||||
res.end(method === 'HEAD' ? null : html)
|
||||
|
|
|
@ -2,7 +2,7 @@ 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')
|
||||
res.setHeader('Content-Type', 'text/html; charset=iso-8859-2')
|
||||
}
|
||||
return {}
|
||||
}
|
||||
|
|
|
@ -71,12 +71,12 @@ export default function ({ app }, suiteName, render, fetch) {
|
|||
|
||||
test('default Content-Type', async () => {
|
||||
const res = await fetch('/stateless')
|
||||
expect(res.headers.get('Content-Type')).toMatch('text/html')
|
||||
expect(res.headers.get('Content-Type')).toMatch('text/html; charset=utf-8')
|
||||
})
|
||||
|
||||
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')
|
||||
expect(res.headers.get('Content-Type')).toMatch('text/html; charset=iso-8859-2')
|
||||
})
|
||||
|
||||
test('allows to import .json files', async () => {
|
||||
|
|
Loading…
Reference in a new issue