Merge tag '3.8.0'
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parents e7e2592, f6bbeaf · Browse files · 19 files·+612 added−157 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
19 files+612 added−157 removed
- tests:+545 added−153 removed
- other:+67 added−4 removed
Provenance
- Commit
db4a061- Tree
1af29cc- Author
Douglas Christopher Wilson <doug@somethingdoug.com>- Committer
Douglas Christopher Wilson <doug@somethingdoug.com>- Parent 1
e7e2592- Parent 2
f6bbeaf
19 files changed+612 added−157 removed
modified:lib/response.js+16 added-1 removed
7 unmodified lines8 var escapeHtml = require('escape-html');9 var sign = require('cookie-signature').sign;10 var normalizeType = require('./utils').normalizeType;11 var normalizeTypes = require('./utils').normalizeTypes;12+var setCharset = require('./utils').setCharset;13 var contentDisposition = require('./utils').contentDisposition;14 var deprecate = require('./utils').deprecate;15 var etag = require('./utils').etag;16 var statusCodes = http.STATUS_CODES;66 unmodified lines83 84 res.send = function(body){85 var req = this.req;86 var head = 'HEAD' == req.method;87+ var type;88+ var encoding;89 var len;90 91 // settings92 var app = this.app;46 unmodified lines139 this.set('ETag', etag(body));140 }141 }142 143+ // write strings in utf-8144+ if ('string' === typeof body) {145+ encoding = 'utf8';146+ type = this.get('Content-Type');147+148+ // reflect this in content-type149+ if ('string' === typeof type) {150+ this.set('Content-Type', setCharset(type, 'utf-8'));151+ }152+ }153+154 // freshness155 if (req.fresh) this.statusCode = 304;156 157 // strip irrelevant headers4 unmodified lines162 body = '';163 }164 165 // respond152- this.end(head ? null : body);166+ this.end((head ? null : body), encoding);167+168 return this;169 };170 171 /**647 unmodified linesmodified:lib/utils.js+36 added
7 unmodified lines8 var deprecate = require('util').deprecate;9 var proxyaddr = require('proxy-addr');10 11 /**12+ * Simple detection of charset parameter in content-type13+ */14+var charsetRegExp = /;\s*charset\s*=/;15+16+/**17 * Deprecate function, like core `util.deprecate`,18 * but with NODE_ENV and color support.19 *20 * @param {Function} fn170 unmodified lines191 }192 193 return proxyaddr.compile(val || []);194 }195+196+/**197+ * Set the charset in a given Content-Type string.198+ *199+ * @param {String} type200+ * @param {String} charset201+ * @return {String}202+ * @api private203+ */204+205+exports.setCharset = function(type, charset){206+ if (!type || !charset) return type;207+208+ var exists = charsetRegExp.test(type);209+210+ // removing existing charset211+ if (exists) {212+ var parts = type.split(';');213+214+ for (var i = 1; i < parts.length; i++) {215+ if (charsetRegExp.test(';' + parts[i])) {216+ parts.splice(i, 1);217+ break;218+ }219+ }220+221+ type = parts.join(';');222+ }223+224+ return type + '; charset=' + charset;225+};modified:test/acceptance/content-negotiation.js+32 added-5 removed
5 unmodified lines67891011101112131415161819171819202122232425262728293031322233343536373839404142434445464748495 unmodified lines describe('GET /', function(){ it('should default to text/html', function(done){ request(app) .get('/') .expect('<ul><li>Tobi</li><li>Loki</li><li>Jane</li></ul>') .end(done); .expect(200, '<ul><li>Tobi</li><li>Loki</li><li>Jane</li></ul>', done) })
it('should accept to text/plain', function(done){ request(app) .get('/') .set('Accept', 'text/plain') .expect(' - Tobi\n - Loki\n - Jane\n') .end(done); .expect(200, ' - Tobi\n - Loki\n - Jane\n', done) })
it('should accept to application/json', function(done){ request(app) .get('/') .set('Accept', 'application/json') .expect(200, '[{"name":"Tobi"},{"name":"Loki"},{"name":"Jane"}]', done) }) })
describe('GET /users', function(){ it('should default to text/html', function(done){ request(app) .get('/users') .expect(200, '<ul><li>Tobi</li><li>Loki</li><li>Jane</li></ul>', done)}) })
it('should accept to text/plain', function(done){ request(app) .get('/users') .set('Accept', 'text/plain') .expect(200, ' - Tobi\n - Loki\n - Jane\n', done) })
it('should accept to application/json', function(done){ request(app) .get('/users') .set('Accept', 'application/json') .expect(200, '[{"name":"Tobi"},{"name":"Loki"},{"name":"Jane"}]', done) }) })})modified:test/acceptance/cookies.js+41 added-2 removed
16 unmodified lines171819202122232425262728293031323334353637383940414243444546474849505152535455562857585960616263646566676869707172347316 unmodified lines res.headers.should.not.have.property('set-cookie') done() }) })
it('should respond to cookie', function(done){ request(app) .post('/') .send({ remember: 1 }) .expect(302, function(err, res){ if (err) return done(err) request(app) .get('/') .set('Cookie', res.headers['set-cookie'][0]) .expect(200, /Remembered/, done) }) }) })
describe('GET /forget', function(){ it('should clear cookie', function(done){ request(app) .post('/') .send({ remember: 1 }) .expect(302, function(err, res){ if (err) return done(err) request(app) .get('/forget') .set('Cookie', res.headers['set-cookie'][0]) .expect('Set-Cookie', /remember=;/) .expect(302, done) }) }) })
describe('POST /', function(){ it('should set a cookie', function(done){ request(app) .post('/') .send({ remember: 1 }) .end(function(err, res){ .expect(302, function(err, res){ res.headers.should.have.property('set-cookie') done() }) })
it('should no set cookie w/o reminder', function(done){ request(app) .post('/') .send({}) .expect(302, function(err, res){ res.headers.should.not.have.property('set-cookie') done() }) }) })})No newline at end of file})modified:test/acceptance/mvc.js+51 added-13 removed
5 unmodified lines6 describe('GET /', function(){7 it('should redirect to /users', function(done){8 request(app)9 .get('/')10+ .expect('Location', '/users')11+ .expect(302, done)12+ })13+ })14+15+ describe('GET /pet/0', function(){16+ it('should get pet', function(done){17+ request(app)18+ .get('/pet/0')19+ .expect(200, /Tobi/, done)20+ })21+ })22+23+ describe('GET /pet/0/edit', function(){24+ it('should get pet edit page', function(done){25+ request(app)26+ .get('/pet/0/edit')27+ .expect(/<form/)28+ .expect(200, /Tobi/, done)29+ })30+ })31+32+ describe('PUT /pet/2', function(){33+ it('should update the pet', function(done){34+ request(app)35+ .put('/pet/3')36+ .send({ pet: { name: 'Boots' } })37 .end(function(err, res){11- res.should.have.status(302);12- res.headers.location.should.include('/users');13- done();38+ if (err) return done(err);39+ request(app)40+ .get('/pet/3/edit')41+ .expect(200, /Boots/, done)42 })43 })44 })45 46 unmodified lines92 describe('GET /user/:id/edit', function(){93 it('should display the edit form', function(done){94 request(app)95 .get('/user/1/edit')68- .end(function(err, res){69- res.text.should.include('<h1>Guillermo</h1>');70- res.text.should.include('value="put"');71- done();72- })96+ .expect(/Guillermo/)97+ .expect(200, /<form/, done)98 })99 })100 101 describe('PUT /user/:id', function(){1 unmodified line103 request(app)104 .put('/user/1')105 .send({ user: { name: 'Tobo' }})106 .end(function(err, res){107+ if (err) return done(err);108 request(app)109 .get('/user/1/edit')84- .end(function(err, res){85- res.text.should.include('<h1>Tobo</h1>');86- done();87- })110+ .expect(200, /Tobo/, done)111 })112 })113 })114+115+ describe('POST /user/:id/pet', function(){116+ it('should create a pet for user', function(done){117+ request(app)118+ .post('/user/2/pet')119+ .send({ pet: { name: 'Snickers' }})120+ .expect('Location', '/user/2')121+ .expect(302, function(err, res){122+ if (err) return done(err)123+ request(app)124+ .get('/user/2')125+ .expect(200, /Snickers/, done)91-})126+ })127+ })128+ })129+})modified:test/acceptance/web-service.js+67 added-6 removed
22 unmodified lines232425262728293031272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991004 unmodified lines1051061071084810922 unmodified lines describe('with a valid api key', function(){ it('should respond users json', function(done){ request(app) .get('/api/users?api-key=foo') .end(function(err, res){ res.should.be.json; res.text.should.equal('[{"name":"tobi"},{"name":"loki"},{"name":"jane"}]'); done(); }); .expect('Content-Type', 'application/json; charset=utf-8') .expect(200, '[{"name":"tobi"},{"name":"loki"},{"name":"jane"}]', done) }) }) })
describe('GET /api/repos', function(){ describe('without an api key', function(){ it('should respond with 400 bad request', function(done){ request(app) .get('/api/repos') .expect(400, done); }) })
describe('with an invalid api key', function(){ it('should respond with 401 unauthorized', function(done){ request(app) .get('/api/repos?api-key=rawr') .expect(401, done); }) })
describe('with a valid api key', function(){ it('should respond repos json', function(done){ request(app) .get('/api/repos?api-key=foo') .expect('Content-Type', 'application/json; charset=utf-8') .expect(/"name":"express"/) .expect(/"url":"http:\/\/github.com\/visionmedia\/express"/) .expect(200, done) }) }) })
describe('GET /api/user/:name/repos', function(){ describe('without an api key', function(){ it('should respond with 400 bad request', function(done){ request(app) .get('/api/user/loki/repos') .expect(400, done); }) })
describe('with an invalid api key', function(){ it('should respond with 401 unauthorized', function(done){ request(app) .get('/api/user/loki/repos?api-key=rawr') .expect(401, done); }) })
describe('with a valid api key', function(){ it('should respond user repos json', function(done){ request(app) .get('/api/user/loki/repos?api-key=foo') .expect('Content-Type', 'application/json; charset=utf-8') .expect(/"name":"stylus"/) .expect(/"url":"http:\/\/github.com\/learnboost\/stylus"/) .expect(200, done) })
it('should 404 with unknown user', function(done){ request(app) .get('/api/user/bob/repos?api-key=foo') .expect(404, done) }) }) })
describe('when requesting an invalid route', function(){ it('should respond with 404 json', function(done){ request(app) .get('/api/something?api-key=bar')4 unmodified lines done(); }); }) })})No newline at end of file})modified:test/app.js+9 added
82 unmodified lines83 app.enabled('view cache').should.be.true;84 process.env.NODE_ENV = 'test';85 })86 })87+88+describe('without NODE_ENV', function(){89+ it('should default to development', function(){90+ process.env.NODE_ENV = '';91+ var app = express();92+ app.get('env').should.equal('development');93+ process.env.NODE_ENV = 'test';94+ })95+})modified:test/app.param.js+43 added
35 unmodified lines36 .expect(404, done);37 });38 39 })40+41+ it('should fail if not given fn', function(){42+ var app = express();43+ app.param.bind(app, ':name', 'bob').should.throw();44+ })45 })46 47 describe('.param(names, fn)', function(){48 it('should map the array', function(done){106 unmodified lines155 request(app)156 .get('/foo/bob')157 .expect('2 2 foo,bob', done);158 })159+160+ it('should catch thrown error', function(done){161+ var app = express();162+163+ app.param('id', function(req, res, next, id){164+ throw new Error('err!');165+ });166+167+ app.get('/user/:id', function(req, res){168+ var id = req.params.id;169+ res.send('' + id);170+ });171+172+ request(app)173+ .get('/user/123')174+ .expect(500, done);175+ })176+177+ it('should defer to next route', function(done){178+ var app = express();179+180+ app.param('id', function(req, res, next, id){181+ next('route');182+ });183+184+ app.get('/user/:id', function(req, res){185+ var id = req.params.id;186+ res.send('' + id);187+ });188+189+ app.get('/:name/123', function(req, res){190+ res.send('name');191+ });192+193+ request(app)194+ .get('/user/123')195+ .expect('name', done);196+ })197 })198 })modified:test/app.render.js+115 added
52 unmodified lines53 done();54 })55 })56 57+ it('should handle render error throws', function(done){58+ var app = express();59+60+ function View(name, options){61+ this.name = name;62+ this.path = 'fale';63+ }64+65+ View.prototype.render = function(options, fn){66+ throw new Error('err!');67+ };68+69+ app.set('view', View);70+71+ app.render('something', function(err, str){72+ err.should.be.ok;73+ err.message.should.equal('err!');74+ done();75+ })76+ })77+78 describe('when the file does not exist', function(){79 it('should provide a helpful error', function(done){80 var app = express();81 app.set('views', __dirname + '/fixtures');70 unmodified lines152 done();153 })154 })155 })156+157+ describe('caching', function(){158+ it('should always lookup view without cache', function(done){159+ var app = express();160+ var count = 0;161+162+ function View(name, options){163+ this.name = name;164+ this.path = 'fake';165+ count++;166+ }167+168+ View.prototype.render = function(options, fn){169+ fn(null, 'abstract engine');170+ };171+172+ app.set('view cache', false);173+ app.set('view', View);174+175+ app.render('something', function(err, str){176+ if (err) return done(err);177+ count.should.equal(1);178+ str.should.equal('abstract engine');179+ app.render('something', function(err, str){180+ if (err) return done(err);181+ count.should.equal(2);182+ str.should.equal('abstract engine');183+ done();184+ })185+ })186+ })187+188+ it('should cache with "view cache" setting', function(done){189+ var app = express();190+ var count = 0;191+192+ function View(name, options){193+ this.name = name;194+ this.path = 'fake';195+ count++;196+ }197+198+ View.prototype.render = function(options, fn){199+ fn(null, 'abstract engine');200+ };201+202+ app.set('view cache', true);203+ app.set('view', View);204+205+ app.render('something', function(err, str){206+ if (err) return done(err);207+ count.should.equal(1);208+ str.should.equal('abstract engine');209+ app.render('something', function(err, str){210+ if (err) return done(err);211+ count.should.equal(1);212+ str.should.equal('abstract engine');213+ done();214+ })215+ })216+ })217+ })218 })219 220 describe('.render(name, options, fn)', function(){221 it('should render the template', function(done){35 unmodified lines257 str.should.equal('<p>jane</p>');258 done();259 })260 })261+262+ describe('caching', function(){263+ it('should cache with cache option', function(done){264+ var app = express();265+ var count = 0;266+267+ function View(name, options){268+ this.name = name;269+ this.path = 'fake';270+ count++;271+ }272+273+ View.prototype.render = function(options, fn){274+ fn(null, 'abstract engine');275+ };276+277+ app.set('view cache', false);278+ app.set('view', View);279+280+ app.render('something', {cache: true}, function(err, str){281+ if (err) return done(err);282+ count.should.equal(1);283+ str.should.equal('abstract engine');284+ app.render('something', {cache: true}, function(err, str){285+ if (err) return done(err);286+ count.should.equal(1);287+ str.should.equal('abstract engine');288+ done();289+ })290+ })291+ })292+ })293 })294 })added:test/req.acceptsEncoding.js+36 added
1+2+var express = require('../')3+ , request = require('supertest');4+5+describe('req', function(){6+ describe('.acceptsEncodings', function(){7+ it('should be true if encoding accpeted', function(done){8+ var app = express();9+10+ app.use(function(req, res){11+ req.acceptsEncoding('gzip').should.be.ok;12+ req.acceptsEncoding('deflate').should.be.ok;13+ res.end();14+ });15+16+ request(app)17+ .get('/')18+ .set('Accept-Encoding', ' gzip, deflate')19+ .expect(200, done);20+ })21+22+ it('should be false if encoding not accpeted', function(done){23+ var app = express();24+25+ app.use(function(req, res){26+ req.acceptsEncoding('bogus').should.not.be.ok;27+ res.end();28+ });29+30+ request(app)31+ .get('/')32+ .set('Accept-Encoding', ' gzip, deflate')33+ .expect(200, done);34+ })35+ })36+})added:test/req.acceptsLanguage.js+53 added
1+2+var express = require('../')3+ , request = require('supertest');4+5+describe('req', function(){6+ describe('.acceptsLanguage', function(){7+ it('should be true if language accpeted', function(done){8+ var app = express();9+10+ app.use(function(req, res){11+ req.acceptsLanguage('en-us').should.be.ok;12+ req.acceptsLanguage('en').should.be.ok;13+ res.end();14+ });15+16+ request(app)17+ .get('/')18+ .set('Accept-Language', 'en;q=.5, en-us')19+ .expect(200, done);20+ })21+22+ it('should be false if language not accpeted', function(done){23+ var app = express();24+25+ app.use(function(req, res){26+ req.acceptsLanguage('es').should.not.be.ok;27+ res.end();28+ });29+30+ request(app)31+ .get('/')32+ .set('Accept-Language', 'en;q=.5, en-us')33+ .expect(200, done);34+ })35+36+ describe('when Accept-Language is not present', function(){37+ it('should always return true', function(done){38+ var app = express();39+40+ app.use(function(req, res){41+ req.acceptsLanguage('en').should.be.ok;42+ req.acceptsLanguage('es').should.be.ok;43+ req.acceptsLanguage('jp').should.be.ok;44+ res.end();45+ });46+47+ request(app)48+ .get('/')49+ .expect(200, done);50+ })51+ })52+ })53+})modified:test/req.range.js+8 added-1 removed
1 2+var assert = require('assert');2-var express = require('../');3+var express = require('..');4 5 function req(ret) {6 return {7 get: function(){ return ret }19 unmodified lines27 var ret = [{ start: 0, end: Infinity }];28 ret.type = 'users';29 req('users=0-').range(Infinity).should.eql(ret);30 })31+32+ it('should return undefined if no range', function(){33+ var ret = [{ start: 0, end: 50 }, { start: 60, end: 100 }];34+ ret.type = 'bytes';35+ assert(req('').range(120) === undefined);36+ })37 })38 })modified:test/res.attachment.js+1 added-1 removed
34 unmodified lines35 var app = express();36 37 app.use(function(req, res){38 res.attachment('/path/to/image.png');39- res.send('foo');39+ res.send(new Buffer(4));40 });41 42 request(app)43 .get('/')35 unmodified linesmodified:test/res.json.js+21 added-54 removed
25 unmodified lines26 });27 28 request(app)29 .get('/')30- .expect('Content-Type', 'application/vnd.example+json')30+ .expect('Content-Type', 'application/vnd.example+json; charset=utf-8')31 .expect(200, '{"hello":"world"}', done);32 })33 34 describe('when given primitives', function(){5 unmodified lines40 });41 42 request(app)43 .get('/')44- .end(function(err, res){45- res.headers.should.have.property('content-type', 'application/json');46- res.text.should.equal('null');47- done();48- })44+ .expect('Content-Type', 'application/json; charset=utf-8')45+ .expect(200, 'null', done)46 })47 48 it('should respond with json for Number', function(done){49 var app = express();3 unmodified lines53 });54 55 request(app)56 .get('/')60- .end(function(err, res){61- res.statusCode.should.equal(200);62- res.headers.should.have.property('content-type', 'application/json');63- res.text.should.equal('300');64- done();65- })57+ .expect('Content-Type', 'application/json; charset=utf-8')58+ .expect(200, '300', done)59 })60 61 it('should respond with json for String', function(done){62 var app = express();3 unmodified lines66 });67 68 request(app)69 .get('/')77- .end(function(err, res){78- res.statusCode.should.equal(200);79- res.headers.should.have.property('content-type', 'application/json');80- res.text.should.equal('"str"');81- done();82- })70+ .expect('Content-Type', 'application/json; charset=utf-8')71+ .expect(200, '"str"', done)72 })73 })74 75 describe('when given an array', function(){5 unmodified lines81 });82 83 request(app)84 .get('/')96- .end(function(err, res){97- res.headers.should.have.property('content-type', 'application/json');98- res.text.should.equal('["foo","bar","baz"]');99- done();100- })85+ .expect('Content-Type', 'application/json; charset=utf-8')86+ .expect(200, '["foo","bar","baz"]', done)87 })88 })89 90 describe('when given an object', function(){5 unmodified lines96 });97 98 request(app)99 .get('/')114- .end(function(err, res){115- res.headers.should.have.property('content-type', 'application/json');116- res.text.should.equal('{"name":"tobi"}');117- done();118- })100+ .expect('Content-Type', 'application/json; charset=utf-8')101+ .expect(200, '{"name":"tobi"}', done)102 })103 })104 105 describe('"json replacer" setting', function(){11 unmodified lines117 });118 119 request(app)120 .get('/')138- .end(function(err, res){139- res.text.should.equal('{"name":"tobi"}');140- done();141- });121+ .expect('Content-Type', 'application/json; charset=utf-8')122+ .expect(200, '{"name":"tobi"}', done)123 })124 })125 126 describe('"json spaces" setting', function(){12 unmodified lines139 });140 141 request(app)142 .get('/')162- .end(function(err, res){163- res.text.should.equal('{\n "name": "tobi",\n "age": 2\n}');164- done();165- });143+ .expect('Content-Type', 'application/json; charset=utf-8')144+ .expect(200, '{\n "name": "tobi",\n "age": 2\n}', done)145 })146 })147 })148 6 unmodified lines155 });156 157 request(app)158 .get('/')180- .end(function(err, res){181- res.statusCode.should.equal(201);182- res.headers.should.have.property('content-type', 'application/json');183- res.text.should.equal('{"id":1}');184- done();185- })159+ .expect('Content-Type', 'application/json; charset=utf-8')160+ .expect(201, '{"id":1}', done)161 })162 })163 164 describe('.json(object, status)', function(){5 unmodified lines170 });171 172 request(app)173 .get('/')199- .end(function(err, res){200- res.statusCode.should.equal(201);201- res.headers.should.have.property('content-type', 'application/json');202- res.text.should.equal('{"id":1}');203- done();204- })174+ .expect('Content-Type', 'application/json; charset=utf-8')175+ .expect(201, '{"id":1}', done)176 })177 178 it('should use status as second number for backwards compat', function(done){179 var app = express();3 unmodified lines183 });184 185 request(app)186 .get('/')216- .end(function(err, res){217- res.statusCode.should.equal(201);218- res.headers.should.have.property('content-type', 'application/json');219- res.text.should.equal('200');220- done();221- })187+ .expect('Content-Type', 'application/json; charset=utf-8')188+ .expect(201, '200', done)189 })190 })191 })modified:test/res.jsonp.js+39 added-64 removed
44 unmodified lines45 });46 47 request(app)48 .get('/?callback[a]=something')49- .end(function(err, res){50- res.headers.should.have.property('content-type', 'application/json');51- res.text.should.equal('{"count":1}');52- done();53- })49+ .expect('Content-Type', 'application/json; charset=utf-8')50+ .expect(200, '{"count":1}', done)51 })52 53 it('should allow renaming callback', function(done){54 var app = express();70 unmodified lines125 });126 127 request(app)128 .get('/')132- .expect('Content-Type', 'application/vnd.example+json')129+ .expect('Content-Type', 'application/vnd.example+json; charset=utf-8')130 .expect(200, '{"hello":"world"}', done);131 })132 133 it('should override previous Content-Types with callback', function(done){19 unmodified lines153 });154 155 request(app)156 .get('/')160- .end(function(err, res){161- res.headers.should.have.property('content-type', 'application/json');162- res.text.should.equal('null');163- done();164- })157+ .expect('Content-Type', 'application/json; charset=utf-8')158+ .expect(200, 'null', done)159 })160 })161 162 describe('when given an array', function(){5 unmodified lines168 });169 170 request(app)171 .get('/')178- .end(function(err, res){179- res.headers.should.have.property('content-type', 'application/json');180- res.text.should.equal('["foo","bar","baz"]');181- done();182- })172+ .expect('Content-Type', 'application/json; charset=utf-8')173+ .expect(200, '["foo","bar","baz"]', done)174 })175 })176 177 describe('when given an object', function(){5 unmodified lines183 });184 185 request(app)186 .get('/')196- .end(function(err, res){197- res.headers.should.have.property('content-type', 'application/json');198- res.text.should.equal('{"name":"tobi"}');199- done();200- })187+ .expect('Content-Type', 'application/json; charset=utf-8')188+ .expect(200, '{"name":"tobi"}', done)189 })190 })191 192 describe('when given primitives', function(){5 unmodified lines198 });199 200 request(app)201 .get('/')214- .end(function(err, res){215- res.headers.should.have.property('content-type', 'application/json');216- res.text.should.equal('null');217- done();218- })202+ .expect('Content-Type', 'application/json; charset=utf-8')203+ .expect(200, 'null', done)204 })205 206 it('should respond with json for Number', function(done){207 var app = express();3 unmodified lines211 });212 213 request(app)214 .get('/')230- .end(function(err, res){231- res.statusCode.should.equal(200);232- res.headers.should.have.property('content-type', 'application/json');233- res.text.should.equal('300');234- done();235- })215+ .expect('Content-Type', 'application/json; charset=utf-8')216+ .expect(200, '300', done)217 })218 219 it('should respond with json for String', function(done){220 var app = express();3 unmodified lines224 });225 226 request(app)227 .get('/')247- .end(function(err, res){248- res.statusCode.should.equal(200);249- res.headers.should.have.property('content-type', 'application/json');250- res.text.should.equal('"str"');251- done();252- })228+ .expect('Content-Type', 'application/json; charset=utf-8')229+ .expect(200, '"str"', done)230 })231 })232 233 describe('"json replacer" setting', function(){11 unmodified lines245 });246 247 request(app)248 .get('/')272- .end(function(err, res){273- res.text.should.equal('{"name":"tobi"}');274- done();275- });249+ .expect('Content-Type', 'application/json; charset=utf-8')250+ .expect(200, '{"name":"tobi"}', done)251 })252 })253 254 describe('"json spaces" setting', function(){12 unmodified lines267 });268 269 request(app)270 .get('/')296- .end(function(err, res){297- res.text.should.equal('{\n "name": "tobi",\n "age": 2\n}');298- done();299- });271+ .expect('Content-Type', 'application/json; charset=utf-8')272+ .expect(200, '{\n "name": "tobi",\n "age": 2\n}', done)273 })274 })275 })276 6 unmodified lines283 });284 285 request(app)286 .get('/')314- .end(function(err, res){315- res.statusCode.should.equal(201);316- res.headers.should.have.property('content-type', 'application/json');317- res.text.should.equal('{"id":1}');318- done();319- })287+ .expect('Content-Type', 'application/json; charset=utf-8')288+ .expect(201, '{"id":1}', done)289 })290 })291 292 describe('.jsonp(object, status)', function(){5 unmodified lines298 });299 300 request(app)301 .get('/')333- .end(function(err, res){334- res.statusCode.should.equal(201);335- res.headers.should.have.property('content-type', 'application/json');336- res.text.should.equal('{"id":1}');337- done();338- })302+ .expect('Content-Type', 'application/json; charset=utf-8')303+ .expect(201, '{"id":1}', done)304 })305 306 it('should use status as second number for backwards compat', function(done){307 var app = express();3 unmodified lines311 });312 313 request(app)314 .get('/')350- .end(function(err, res){351- res.statusCode.should.equal(201);352- res.headers.should.have.property('content-type', 'application/json');353- res.text.should.equal('200');354- done();355- })315+ .expect('Content-Type', 'application/json; charset=utf-8')316+ .expect(201, '200', done)317 })318 })319+320+ it('should not override previous Content-Types', function(done){321+ var app = express();322+323+ app.get('/', function(req, res){324+ res.type('application/vnd.example+json');325+ res.jsonp({ hello: 'world' });326+ });327+328+ request(app)329+ .get('/')330+ .expect('content-type', 'application/vnd.example+json; charset=utf-8')331+ .expect(200, '{"hello":"world"}', done)332+ })333 })modified:test/res.send.js+29 added-7 removed
138 unmodified lines139 140 request(app)141 .get('/')142 .expect('Content-Type', 'text/plain; charset=utf-8')143- .expect('hey')144- .expect(200, done);143+ .expect(200, 'hey', done);144 })145+146+ it('should override charset in Content-Type', function(done){147+ var app = express();148+149+ app.use(function(req, res){150+ res.set('Content-Type', 'text/plain; charset=iso-8859-1').send('hey');151+ });152+153+ request(app)154+ .get('/')155+ .expect('Content-Type', 'text/plain; charset=utf-8')156+ .expect(200, 'hey', done);157+ })158+159+ it('should keep charset in Content-Type for Buffers', function(done){160+ var app = express();161+162+ app.use(function(req, res){163+ res.set('Content-Type', 'text/plain; charset=iso-8859-1').send(new Buffer('hi'));164+ });165+166+ request(app)167+ .get('/')168+ .expect('Content-Type', 'text/plain; charset=iso-8859-1')169+ .expect(200, 'hi', done);170+ })171 })172 173 describe('.send(Buffer)', function(){174 it('should send as octet-stream', function(done){54 unmodified lines229 });230 231 request(app)232 .get('/')208- .end(function(err, res){209- res.headers.should.have.property('content-type', 'application/json');210- res.text.should.equal('{"name":"tobi"}');211- done();212- })233+ .expect('Content-Type', 'application/json; charset=utf-8')234+ .expect(200, '{"name":"tobi"}', done)235 })236 })237 238 describe('when the request method is HEAD', function(){182 unmodified linesmodified:.travis.yml+1 added
5 unmodified lines6 allow_failures:7 - node_js: "0.11"8 fast_finish: true9 script: "npm run-script test-travis"10+after_script: "npm install coveralls@2.10.0 && cat ./coverage/lcov.info | coveralls"modified:History.md+12 added
11 unmodified lines12 - `app.set('trust proxy', '10.0.0.1/16')` trust subnet13 - `app.set('trust proxy', '10.0.0.1, 10.0.0.2')` trust list14 - `app.set('trust proxy', false)` turn off15 - `app.set('trust proxy', true)` trust everything16+ * set proper `charset` in `Content-Type` for `res.send`17 * update type-is to 1.2.018 - support suffix matching19 20 4.2.0 / 2014-05-1191 unmodified lines112 - `app.router()` - returns the app Router instance113 - `app.route()` - Proxy to the app's `Router#route()` method to create a new route114 - Router & Route - public API115 116+3.8.0 / 2014-05-21117+==================118+119+ * keep previous `Content-Type` for `res.jsonp`120+ * set proper `charset` in `Content-Type` for `res.send`121+ * update connect to 2.17.1122+ - fix `res.charset` appending charset when `content-type` has one123+ - deps: express-session@1.2.0124+ - deps: morgan@1.1.1125+ - deps: serve-index@1.0.3126+127 3.7.0 / 2014-05-18128 ==================129 130 * proper proxy trust with `app.set('trust proxy', trust)`1335 unmodified linesmodified:package.json+2 added-3 removed
66 unmodified lines67 "debug": "0.8.1"68 },69 "devDependencies": {70 "after": "0.8.1",71- "coveralls": "2.10.0",71 "istanbul": "0.2.10",73- "mocha": "~1.18.2",72+ "mocha": "~1.19.0",73 "should": "~3.3.1",74 "supertest": "~0.12.0",75 "connect-redis": "~2.0.0",76 "ejs": "~1.0.0",14 unmodified lines91 "scripts": {92 "prepublish": "npm prune",93 "test": "mocha --require test/support/env --reporter dot --check-leaks test/ test/acceptance/",94 "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --require test/support/env --reporter dot --check-leaks test/ test/acceptance/",96- "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --require test/support/env --reporter spec --check-leaks test/ test/acceptance/ && (cat ./coverage/lcov.info | coveralls || true)"95+ "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --require test/support/env --reporter spec --check-leaks test/ test/acceptance/"96 }97 }