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
6 changes: 3 additions & 3 deletions lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -652,8 +652,9 @@ 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()`.
* This method is a generic header setter: for `Content-Type` it does not
* perform any MIME lookup or charset injection. If you want shorthand
* resolution and charset handling, use `res.type()`.
*
* @param {String|Object} field
* @param {String|Array} val
Expand All @@ -673,7 +674,6 @@ res.header = function header(field, val) {
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 @@ -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
27 changes: 27 additions & 0 deletions test/res.set.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,33 @@ describe('res', function(){
.end(done);
})

it('should not add charset when Content-Type is set without one', function (done) {
var app = express();

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

request(app)
.get('/')
.expect('Content-Type', 'text/plain')
.expect(200, done);
})

it('should not resolve shorthand Content-Type values', function (done) {
var app = express();

app.use(function (req, res) {
// "html" looks like a shorthand; res.set should be pass-through.
res.set('Content-Type', 'html').end();
});

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

it('should coerce to a string', function (done) {
var app = express();

Expand Down