diff --git a/lib/response.js b/lib/response.js index 7a2f0ecce56..1a4d2deff26 100644 --- a/lib/response.js +++ b/lib/response.js @@ -126,7 +126,6 @@ res.send = function send(body) { var chunk = body; var encoding; var req = this.req; - var type; // settings var app = this.app; @@ -134,7 +133,12 @@ res.send = function send(body) { switch (typeof chunk) { // string defaulting to html case 'string': - if (!this.get('Content-Type')) { + encoding = 'utf8'; + const type = this.get('Content-Type'); + + if (typeof type === 'string') { + this.set('Content-Type', setCharset(type, 'utf-8')); + } else { this.type('html'); } break; @@ -153,17 +157,6 @@ res.send = function send(body) { break; } - // write strings in utf-8 - if (typeof chunk === 'string') { - encoding = 'utf8'; - type = this.get('Content-Type'); - - // reflect this in content-type - if (typeof type === 'string') { - this.set('Content-Type', setCharset(type, 'utf-8')); - } - } - // determine if ETag should be generated var etagFn = app.get('etag fn') var generateETag = !this.get('ETag') && typeof etagFn === 'function'