Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 3 additions & 8 deletions lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ res.json = function json(obj) {

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

return this.send(body);
Expand Down Expand Up @@ -271,7 +271,7 @@ res.jsonp = function jsonp(obj) {
// content-type
if (!this.get('Content-Type')) {
this.set('X-Content-Type-Options', 'nosniff');
this.set('Content-Type', 'application/json');
this.type('json');
}

// fixup callback
Expand All @@ -282,7 +282,7 @@ res.jsonp = function jsonp(obj) {
// jsonp
if (typeof callback === 'string' && callback.length !== 0) {
this.set('X-Content-Type-Options', 'nosniff');
this.set('Content-Type', 'text/javascript');
this.type('text/javascript');

// restrict callback charset
callback = callback.replace(/[^\[\]\w$.]/g, '');
Expand Down Expand Up @@ -655,9 +655,6 @@ res.append = function append(field, val) {
*
* Aliased as `res.header()`.
*
* When the set header is "Content-Type", the type is expanded to include
* the charset if not present using `mime.contentType()`.
*
* @param {String|Object} field
* @param {String|Array} val
* @return {ServerResponse} for chaining
Expand All @@ -671,12 +668,10 @@ 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);
Expand Down
4 changes: 2 additions & 2 deletions test/res.send.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,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 @@ -213,7 +213,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