Keep previous Content-Type for res.jsonp

backport of commit be997fd654
This commit is contained in:
Alberto Leal 2014-05-02 15:33:09 -03:00 committed by Douglas Christopher Wilson
parent b0f72e13d9
commit 084f5d891b
3 changed files with 20 additions and 1 deletions

View File

@ -1,6 +1,7 @@
3.x
===
* keep previous `Content-Type` for `res.jsonp`
* update connect to 2.17.1
- fix `res.charset` appending charset when `content-type` has one
- deps: express-session@1.2.0

View File

@ -248,7 +248,7 @@ res.jsonp = function(obj){
// content-type
this.charset = this.charset || 'utf-8';
this.set('Content-Type', 'application/json');
this.get('Content-Type') || this.set('Content-Type', 'application/json');
// fixup callback
if (Array.isArray(callback)) {

View File

@ -334,4 +334,22 @@ describe('res', function(){
})
})
})
it('should not override previous Content-Types', function(done){
var app = express();
app.get('/', function(req, res){
res.type('application/vnd.example+json');
res.jsonp({ hello: 'world' });
});
request(app)
.get('/')
.end(function(err, res){
res.statusCode.should.equal(200);
res.headers.should.have.property('content-type', 'application/vnd.example+json');
res.text.should.equal('{"hello":"world"}');
done();
})
})
})