From 732696e840eeaa32d83dc68adbe9ad075291d0e2 Mon Sep 17 00:00:00 2001 From: Patryk Date: Wed, 6 Dec 2017 01:00:58 +0100 Subject: [PATCH] Add a charset to the default Content-Type (#3333) --- server/render.js | 2 +- test/integration/basic/pages/custom-encoding.js | 2 +- test/integration/basic/test/rendering.js | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/server/render.js b/server/render.js index eabcd659..10ee5f01 100644 --- a/server/render.js +++ b/server/render.js @@ -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) diff --git a/test/integration/basic/pages/custom-encoding.js b/test/integration/basic/pages/custom-encoding.js index e091c3c0..89c024d3 100644 --- a/test/integration/basic/pages/custom-encoding.js +++ b/test/integration/basic/pages/custom-encoding.js @@ -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 {} } diff --git a/test/integration/basic/test/rendering.js b/test/integration/basic/test/rendering.js index 603f24bc..20b69243 100644 --- a/test/integration/basic/test/rendering.js +++ b/test/integration/basic/test/rendering.js @@ -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 () => {