Skip to content

Commit 55b4fc0

Browse files
committed
Fixed content-type of text plain files.
1 parent bb81c2e commit 55b4fc0

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const REG_SANITIZE_BACKSLASH = /\/\//g;
5757
const REG_WEBSOCKET_ERROR = /ECONNRESET|EHOSTUNREACH|EPIPE|is closed/gi;
5858
const REG_SCRIPTCONTENT = /\<|\>|;/;
5959
const REG_HTTPHTTPS = /^(\/)?(http|https)\:\/\//i;
60+
const REG_TEXTAPPLICATION = /text|application/;
6061
const REQUEST_PROXY_FLAGS = ['post', 'json'];
6162
const EMPTYARRAY = [];
6263
const EMPTYOBJECT = {};
@@ -5011,6 +5012,8 @@ Framework.prototype.responseFile = function(req, res, filename, downloadName, he
50115012
returnHeaders.Vary = 'Accept-Encoding';
50125013

50135014
returnHeaders[RESPONSE_HEADER_CONTENTTYPE] = contentType;
5015+
if (REG_TEXTAPPLICATION.test(contentType))
5016+
returnHeaders[RESPONSE_HEADER_CONTENTTYPE] += '; charset=utf-8';
50145017

50155018
if (canCache && !res.getHeader('Expires'))
50165019
returnHeaders.Expires = DATE_EXPIRES;
@@ -5976,7 +5979,7 @@ Framework.prototype.responseContent = function(req, res, code, contentBody, cont
59765979
else
59775980
returnHeaders[RESPONSE_HEADER_CACHECONTROL] = 'private';
59785981

5979-
if ((/text|application/).test(contentType))
5982+
if (REG_TEXTAPPLICATION.test(contentType))
59805983
contentType += '; charset=utf-8';
59815984

59825985
returnHeaders[RESPONSE_HEADER_CONTENTTYPE] = contentType;
@@ -5993,9 +5996,7 @@ Framework.prototype.responseContent = function(req, res, code, contentBody, cont
59935996

59945997
if (gzip) {
59955998
res.writeHead(code, returnHeaders);
5996-
zlib.gzip(new Buffer(contentBody), function(err, data) {
5997-
res.end(data, ENCODING);
5998-
});
5999+
zlib.gzip(new Buffer(contentBody), (err, data) => res.end(data, ENCODING));
59996000
self._request_stats(false, req.isStaticFile);
60006001
if (!req.isStaticFile)
60016002
self.emit('request-end', req, res);

0 commit comments

Comments
 (0)