Skip to content

Commit

Permalink
remove res.charset usage
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanong committed Mar 8, 2014
1 parent 3228fd3 commit 2064f41
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
12 changes: 2 additions & 10 deletions lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions test/res.format.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,20 @@ 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);
})

it('should set the correct charset for the Content-Type', function() {
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('/')
Expand Down

0 comments on commit 2064f41

Please sign in to comment.