Fix Content-Length header in various response helpers
This commit is contained in:
parent
ff14e7d28d
commit
2ac8dc554e
|
@ -5,7 +5,7 @@ const { getContentType } = require('./FileUtils')
|
||||||
const sendText = (res, statusCode, text) => {
|
const sendText = (res, statusCode, text) => {
|
||||||
res.writeHead(statusCode, {
|
res.writeHead(statusCode, {
|
||||||
'Content-Type': 'text/plain',
|
'Content-Type': 'text/plain',
|
||||||
'Content-Length': text.length
|
'Content-Length': Buffer.byteLength(text)
|
||||||
})
|
})
|
||||||
|
|
||||||
res.end(text)
|
res.end(text)
|
||||||
|
@ -16,7 +16,7 @@ const sendJSON = (res, json, maxAge = 0, statusCode = 200) => {
|
||||||
|
|
||||||
res.writeHead(statusCode, {
|
res.writeHead(statusCode, {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Content-Length': text.length,
|
'Content-Length': Buffer.byteLength(text),
|
||||||
'Cache-Control': `public, max-age=${maxAge}`
|
'Cache-Control': `public, max-age=${maxAge}`
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ const sendServerError = (res, error) =>
|
||||||
const sendHTML = (res, html, maxAge = 0, statusCode = 200) => {
|
const sendHTML = (res, html, maxAge = 0, statusCode = 200) => {
|
||||||
res.writeHead(statusCode, {
|
res.writeHead(statusCode, {
|
||||||
'Content-Type': 'text/html',
|
'Content-Type': 'text/html',
|
||||||
'Content-Length': html.length,
|
'Content-Length': Buffer.byteLength(html),
|
||||||
'Cache-Control': `public, max-age=${maxAge}`
|
'Cache-Control': `public, max-age=${maxAge}`
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ const sendRedirect = (res, relativeLocation, maxAge = 0, statusCode = 302) => {
|
||||||
|
|
||||||
res.writeHead(statusCode, {
|
res.writeHead(statusCode, {
|
||||||
'Content-Type': 'text/html',
|
'Content-Type': 'text/html',
|
||||||
'Content-Length': html.length,
|
'Content-Length': Buffer.byteLength(html),
|
||||||
'Cache-Control': `public, max-age=${maxAge}`,
|
'Cache-Control': `public, max-age=${maxAge}`,
|
||||||
'Location': encodeURI(location)
|
'Location': encodeURI(location)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue