From 2064f412cbadfe64e84f8a40f3edb0c2a98bb34d Mon Sep 17 00:00:00 2001 From: Jonathan Ong Date: Fri, 7 Mar 2014 16:46:54 -0800 Subject: [PATCH] remove res.charset usage --- lib/response.js | 12 ++---------- test/res.format.js | 6 +++--- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/lib/response.js b/lib/response.js index 76ccf7e3..ffc92a83 100644 --- a/lib/response.js +++ b/lib/response.js @@ -106,10 +106,7 @@ res.send = function(body){ break; // string defaulting to html case 'string': - if (!this.get('Content-Type')) { - this.charset = this.charset || 'utf-8'; - this.type('html'); - } + if (!this.get('Content-Type')) this.type('html'); break; case 'boolean': case 'object': @@ -189,7 +186,6 @@ res.json = function(obj){ var body = JSON.stringify(obj, replacer, spaces); // content-type - this.charset = this.charset || 'utf-8'; this.get('Content-Type') || this.set('Content-Type', 'application/json'); return this.send(body); @@ -233,7 +229,6 @@ res.jsonp = function(obj){ var callback = this.req.query[app.get('jsonp callback name')]; // content-type - this.charset = this.charset || 'utf-8'; this.set('Content-Type', 'application/json'); // jsonp @@ -467,10 +462,7 @@ res.format = function(obj){ this.vary("Accept"); if (key) { - var type = normalizeType(key).value; - var charset = mime.charsets.lookup(type); - if (charset) type += '; charset=' + charset; - this.set('Content-Type', type); + this.set('Content-Type', normalizeType(key).value); obj[key](req, this, next); } else if (fn) { fn(); diff --git a/test/res.format.js b/test/res.format.js index b6eb199d..5495410c 100644 --- a/test/res.format.js +++ b/test/res.format.js @@ -93,7 +93,7 @@ function test(app) { request(app) .get('/') .set('Accept', 'text/html; q=.5, text/plain') - .expect('Content-Type', 'text/plain; charset=UTF-8') + .expect('Content-Type', 'text/plain; charset=utf-8') .expect('hey', done); }) @@ -101,12 +101,12 @@ function test(app) { request(app) .get('/') .set('Accept', 'text/html') - .expect('Content-Type', 'text/html; charset=UTF-8'); + .expect('Content-Type', 'text/html; charset=utf-8'); request(app) .get('/') .set('Accept', 'text/plain') - .expect('Content-Type', 'text/plain; charset=UTF-8'); + .expect('Content-Type', 'text/plain; charset=utf-8'); request(app) .get('/')