From 2ac8dc554ede4697754b570930f645128f8385ab Mon Sep 17 00:00:00 2001 From: MICHAEL JACKSON Date: Thu, 1 Jun 2017 09:54:44 -0500 Subject: [PATCH] Fix Content-Length header in various response helpers --- server/middleware/ResponseUtils.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server/middleware/ResponseUtils.js b/server/middleware/ResponseUtils.js index 2a8ec29..0a1f77c 100644 --- a/server/middleware/ResponseUtils.js +++ b/server/middleware/ResponseUtils.js @@ -5,7 +5,7 @@ const { getContentType } = require('./FileUtils') const sendText = (res, statusCode, text) => { res.writeHead(statusCode, { 'Content-Type': 'text/plain', - 'Content-Length': text.length + 'Content-Length': Buffer.byteLength(text) }) res.end(text) @@ -16,7 +16,7 @@ const sendJSON = (res, json, maxAge = 0, statusCode = 200) => { res.writeHead(statusCode, { 'Content-Type': 'application/json', - 'Content-Length': text.length, + 'Content-Length': Buffer.byteLength(text), 'Cache-Control': `public, max-age=${maxAge}` }) @@ -35,7 +35,7 @@ const sendServerError = (res, error) => const sendHTML = (res, html, maxAge = 0, statusCode = 200) => { res.writeHead(statusCode, { 'Content-Type': 'text/html', - 'Content-Length': html.length, + 'Content-Length': Buffer.byteLength(html), 'Cache-Control': `public, max-age=${maxAge}` }) @@ -49,7 +49,7 @@ const sendRedirect = (res, relativeLocation, maxAge = 0, statusCode = 302) => { res.writeHead(statusCode, { 'Content-Type': 'text/html', - 'Content-Length': html.length, + 'Content-Length': Buffer.byteLength(html), 'Cache-Control': `public, max-age=${maxAge}`, 'Location': encodeURI(location) })