Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ res.json = function json(obj) {

// content-type
if (!this.get('Content-Type')) {
this.set('Content-Type', 'application/json');
this.set('Content-Type', 'application/json; charset=utf-8');
}

return this.send(body);
Expand Down Expand Up @@ -668,14 +668,6 @@ res.header = function header(field, val) {
? val.map(String)
: String(val);

// add charset to content-type
if (field.toLowerCase() === 'content-type') {
if (Array.isArray(value)) {
throw new TypeError('Content-Type cannot be set to an Array');
}
value = mime.contentType(value)
}

this.setHeader(field, value);
} else {
for (var key in field) {
Expand Down
4 changes: 2 additions & 2 deletions test/res.send.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ describe('res', function(){

request(app)
.get('/')
.expect('Content-Type', 'text/plain; charset=utf-8')
.expect('Content-Type', 'text/plain')
.expect(200, 'hey', done);
})

Expand All @@ -187,7 +187,7 @@ describe('res', function(){

request(app)
.get("/")
.expect("Content-Type", "text/plain; charset=utf-8")
.expect("Content-Type", "text/plain")
.expect(200, "hey", done);
})

Expand Down
17 changes: 9 additions & 8 deletions test/res.set.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,31 +61,32 @@ describe('res', function(){
.expect(200, '["123","456"]', done);
})

it('should not set a charset of one is already set', function (done) {
it('should set Content-Type without mime lookup', function (done) {
var app = express();

app.use(function (req, res) {
res.set('Content-Type', 'text/html; charset=lol');
res.set('Content-Type', 'text/html');
res.end();
});

request(app)
.get('/')
.expect('Content-Type', 'text/html; charset=lol')
.expect('Content-Type', 'text/html')
.expect(200, done);
})

it('should throw when Content-Type is an array', function (done) {
var app = express()
it('should not perform mime lookup for extension-like values', function (done) {
var app = express();

app.use(function (req, res) {
res.set('Content-Type', ['text/html'])
res.end()
res.set('Content-Type', 'html');
res.end();
});

request(app)
.get('/')
.expect(500, /TypeError: Content-Type cannot be set to an Array/, done)
.expect('Content-Type', 'html')
.expect(200, done);
})
})

Expand Down