1
0
Fork 0
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:
Patryk 2017-12-06 01:00:58 +01:00 committed by Tim Neutkens
parent e2bcb039cf
commit 732696e840
3 changed files with 4 additions and 4 deletions

View file

@ -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)

View file

@ -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 {}
}

View file

@ -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 () => {