Merge tag '3.9.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 311e83e, 0dc5836 · Browse files · 50 files·+600 added−198 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
50 files+600 added−198 removed
- tests:+361 added−123 removed
- other:+239 added−75 removed
Provenance
- Commit
db4448d- Tree
5d852f3- Author
Douglas Christopher Wilson <doug@somethingdoug.com>- Committer
Douglas Christopher Wilson <doug@somethingdoug.com>- Parent 1
311e83e- Parent 2
0dc5836
50 files changed+600 added−198 removed
modified:examples/auth/app.js+1 added
119 unmodified linesExpand all120121122123124125126127128119 unmodified linesExpand all } });});
/* istanbul ignore next */if (!module.parent) { app.listen(3000); console.log('Express started on port 3000');}modified:examples/big-view/index.js+5 added-2 removed
22 unmodified lines232425262728272829303122 unmodified linesapp.get('/', function(req, res){ res.render('pets', { pets: pets });});
/* istanbul ignore next */if (!module.parent) {app.listen(3000);console.log('Express listening on port 3000'); app.listen(3000); console.log('Express started on port 3000');}modified:examples/content-negotiation/index.js+2 added-1 removed
35 unmodified lines36 }37 38 app.get('/users', format('./users'));39 40+/* istanbul ignore next */41 if (!module.parent) {42 app.listen(3000);42- console.log('listening on port 3000');43+ console.log('Express started on port 3000');44 }modified:examples/cookie-sessions/index.js+2 added-1 removed
21 unmodified lines2223242526272828293021 unmodified lines var n = req.session.count++; res.send('viewed ' + n + ' times\n');}
/* istanbul ignore next */if (!module.parent) { app.listen(3000); console.log('Express server listening on port 3000'); console.log('Express started on port 3000');}modified:examples/cookies/app.js+3 added-3 removed
7 unmodified lines8 var cookieParser = require('cookie-parser');9 var bodyParser = require('body-parser');10 11 // custom log format12-if ('test' != process.env.NODE_ENV)13- app.use(logger(':method :url'));12+if ('test' != process.env.NODE_ENV) app.use(logger(':method :url'));13 14 // parses request cookies, populating15 // req.cookies and req.signedCookies16 // when the secret is passed, used23 unmodified lines40 if (req.body.remember) res.cookie('remember', 1, { maxAge: minute });41 res.redirect('back');42 });43 44+/* istanbul ignore next */45-if (!module.parent){45+if (!module.parent) {46 app.listen(3000);47 console.log('Express started on port 3000');48 }modified:examples/downloads/app.js+1 added
36 unmodified lines37 next(err);38 }39 });40 41+/* istanbul ignore next */42 if (!module.parent) {43 app.listen(3000);44 console.log('Express started on port 3000');45 }modified:examples/ejs/index.js+2 added-1 removed
41 unmodified lines42 header: "Some users"43 });44 });45 46+/* istanbul ignore next */47 if (!module.parent) {48 app.listen(3000);48- console.log('Express app started on port 3000');49+ console.log('Express started on port 3000');50 }modified:examples/error/index.js+1 added
38 unmodified lines39 // if it were above it would not receive errors40 // from app.get() etc41 app.use(error);42 43+/* istanbul ignore next */44 if (!module.parent) {45 app.listen(3000);46 console.log('Express started on port 3000');47 }modified:examples/error-pages/index.js+3 added-4 removed
16 unmodified lines17 app.enable('verbose errors');18 19 // disable them in production20 // use $ NODE_ENV=production node examples/error-pages21-if ('production' == app.settings.env) {22- app.disable('verbose errors');23-}21+if ('production' == app.settings.env) app.disable('verbose errors');22 23 silent || app.use(logger('dev'));24 25 // Routes70 unmodified lines96 res.render('500', { error: err });97 });98 99 100+/* istanbul ignore next */101 if (!module.parent) {102 app.listen(3000);104- silent || console.log('Express started on port 3000');103+ console.log('Express started on port 3000');104 }modified:examples/expose-data-to-client/index.js+5 added-2 removed
55 unmodified lines56 res.locals.expose.user = req.user;57 res.render('page');58 });59 60+/* istanbul ignore next */61+if (!module.parent) {60-app.listen(3000);61-console.log('app listening on port 3000');62+ app.listen(3000);63+ console.log('Express started on port 3000');64+}modified:examples/hello-world/index.js+5 added-2 removed
4 unmodified lines5 app.get('/', function(req, res){6 res.send('Hello World');7 });8 9+/* istanbul ignore next */10+if (!module.parent) {9-app.listen(3000);10-console.log('Express started on port 3000');11+ app.listen(3000);12+ console.log('Express started on port 3000');13+}modified:examples/jade/index.js+5 added-2 removed
42 unmodified lines43 app.use(function(err, req, res, next) {44 res.send(err.stack);45 });46 47+/* istanbul ignore next */48+if (!module.parent) {47-app.listen(3000);48-console.log('Express app started on port 3000');49+ app.listen(3000);50+ console.log('Express started on port 3000');51+}modified:examples/markdown/index.js+1 added
36 unmodified lines37 app.get('/fail', function(req, res){38 res.render('missing', { title: 'Markdown Example' });39 });40 41+/* istanbul ignore next */42 if (!module.parent) {43 app.listen(3000);44 console.log('Express started on port 3000');45 }modified:examples/multipart/index.js+1 added
51 unmodified lines52 // parse the form53 form.parse(req);54 });55 56+/* istanbul ignore next */57 if (!module.parent) {58 app.listen(4000);59 console.log('Express started on port 3000');60 }modified:examples/mvc/index.js+2 added-1 removed
91 unmodified lines92 app.use(function(req, res, next){93 res.status(404).render('404', { url: req.originalUrl });94 });95 96+/* istanbul ignore next */97 if (!module.parent) {98 app.listen(3000);98- console.log('\n listening on port 3000\n');99+ console.log('Express started on port 3000');100 }modified:examples/online/index.js+5 added-2 removed
47 unmodified lines48 res.send('<p>Users online: ' + ids.length + '</p>' + list(ids));49 });50 });51 52+/* istanbul ignore next */53+if (!module.parent) {52-app.listen(3000);53-console.log('listening on port 3000');54+ app.listen(3000);55+ console.log('Express started on port 3000');56+}modified:examples/params/app.js+4 added-3 removed
16 unmodified lines17 18 // Convert :to and :from to integers19 20 app.param(['to', 'from'], function(req, res, next, num, name){21- req.params[name] = num = parseInt(num, 10);22- if( isNaN(num) ){21+ req.params[name] = parseInt(num, 10);22+ if( isNaN(req.params[name]) ){23 next(new Error('failed to parseInt '+num));24 } else {25 next();26 }35 unmodified lines62 var names = users.map(function(user){ return user.name; });63 res.send('users ' + names.slice(from, to).join(', '));64 });65 66+/* istanbul ignore next */67 if (!module.parent) {68 app.listen(3000);69 console.log('Express started on port 3000');69-}70+}modified:examples/resource/app.js+7 added-4 removed
15 unmodified lines16 var format = req.params.format;17 obj.range(req, res, a, b, format);18 });19 this.get(path + '/:id', obj.show);20- this.delete(path + '/:id', obj.destroy);20+ this.delete(path + '/:id', function(req, res){21+ var id = parseInt(req.params.id, 10);22+ obj.destroy(req, res, id);23+ });24 };25 26 // Fake records27 14 unmodified lines42 },43 show: function(req, res){44 res.send(users[req.params.id] || { error: 'Cannot find user' });45 },43- destroy: function(req, res){44- var id = req.params.id;46+ destroy: function(req, res, id){47 var destroyed = id in users;48 delete users[id];49 res.send(destroyed ? 'destroyed' : 'Cannot find user');50 },34 unmodified lines85 , '</ul>'86 ].join('\n'));87 });88 89+/* istanbul ignore next */90 if (!module.parent) {91 app.listen(3000);92 console.log('Express started on port 3000');90-}93+}modified:examples/route-map/index.js+5 added-1 removed
63 unmodified lines64 }65 }66 });67 68+/* istanbul ignore next */69+if (!module.parent) {68-app.listen(3000);70+ app.listen(3000);71+ console.log('Express started on port 3000');72+}modified:examples/route-middleware/index.js+5 added-2 removed
79 unmodified lines80 app.delete('/user/:id', loadUser, andRestrictTo('admin'), function(req, res){81 res.send('Deleted user ' + req.user.name);82 });83 84+/* istanbul ignore next */85+if (!module.parent) {84-app.listen(3000);85-console.log('Express app started on port 3000');86+ app.listen(3000);87+ console.log('Express started on port 3000');88+}modified:examples/route-separation/index.js+5 added-2 removed
35 unmodified lines36 // Posts37 38 app.get('/posts', post.list);39 40+/* istanbul ignore next */41+if (!module.parent) {40-app.listen(3000);41-console.log('Express app started on port 3000');42+ app.listen(3000);43+ console.log('Express started on port 3000');44+}modified:examples/search/index.js+5 added-2 removed
55 unmodified lines56 app.get('/client.js', function(req, res){57 res.sendfile(__dirname + '/client.js');58 });59 60+/* istanbul ignore next */61+if (!module.parent) {60-app.listen(3000);61-console.log('app listening on port 3000');62+ app.listen(3000);63+ console.log('Express started on port 3000');64+}modified:examples/session/index.js+5 added-2 removed
25 unmodified lines26 }27 res.send(body + '<p>viewed <strong>' + req.session.views + '</strong> times.</p>');28 });29 30+/* istanbul ignore next */31+if (!module.parent) {30-app.listen(3000);31-console.log('Express app started on port 3000');32+ app.listen(3000);33+ console.log('Express started on port 3000');34+}modified:examples/vhost/index.js+5 added-2 removed
42 unmodified lines43 44 app.use(vhost('*.example.com', redirect)); // Serves all subdomains via Redirect app45 app.use(vhost('example.com', main)); // Serves top level domain via Main server app46 47+/* istanbul ignore next */48+if (!module.parent) {47-app.listen(3000);48-console.log('Express app started on port 3000');49+ app.listen(3000);50+ console.log('Express started on port 3000');51+}modified:examples/view-constructor/index.js+1 added
38 unmodified lines39 // rendering a view from https://github.com/visionmedia/express/blob/master/Readme.md40 res.render('Readme.md');41 });42 43+/* istanbul ignore next */44 if (!module.parent) {45 app.listen(3000);46 console.log('Express started on port 3000');47 }modified:examples/view-locals/index.js+5 added-2 removed
143 unmodified lines144 });145 146 */147 148+/* istanbul ignore next */149+if (!module.parent) {148-app.listen(3000);149-console.log('Application listening on port 3000');150+ app.listen(3000);151+ console.log('Express started on port 3000');152+}modified:examples/web-service/index.js+2 added-1 removed
101 unmodified lines102 app.use(function(req, res){103 res.send(404, { error: "Lame, can't find that" });104 });105 106+/* istanbul ignore next */107 if (!module.parent) {108 app.listen(3000);108- console.log('Express server listening on port 3000');109+ console.log('Express started on port 3000');110 }modified:lib/application.js+19 added-9 removed
9 unmodified lines10 var query = require('./middleware/query');11 var debug = require('debug')('express:application');12 var View = require('./view');13 var http = require('http');14+var compileETag = require('./utils').compileETag;15 var compileTrust = require('./utils').compileTrust;16 var deprecate = require('./utils').deprecate;17 18 /**27 unmodified lines46 47 app.defaultConfiguration = function(){48 // default settings49 this.enable('x-powered-by');49- this.enable('etag');50+ this.set('etag', 'weak');51 var env = process.env.NODE_ENV || 'development';52 this.set('env', env);53 this.set('subdomain offset', 2);54 this.set('trust proxy', false);250 unmodified lines305 * @api public306 */307 308 app.set = function(setting, val){308- if (1 == arguments.length) {309+ if (arguments.length === 1) {310+ // app.get(setting)311 return this.settings[setting];310- } else {311- this.settings[setting] = val;312+ }313 313- if (setting === 'trust proxy') {314- debug('compile trust proxy %j', val);315- this.set('trust proxy fn', compileTrust(val));316- }314+ // set value315+ this.settings[setting] = val;316 318- return this;317+ // trigger matched settings318+ switch (setting) {319+ case 'etag':320+ debug('compile etag %s', val);321+ this.set('etag fn', compileETag(val));322+ break;323+ case 'trust proxy':324+ debug('compile trust proxy %s', val);325+ this.set('trust proxy fn', compileTrust(val));326+ break;327 }328+329+ return this;330 };331 332 /**333 * Return the app's absolute pathname218 unmodified linesmodified:lib/response.js+17 added-16 removed
10 unmodified lines11 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;15 var statusCodes = http.STATUS_CODES;16 var cookie = require('cookie');17 var send = require('send');18 var basename = path.basename;104 unmodified lines123 }124 break;125 }126 128- // populate Content-Length129- if (undefined !== body && !this.get('Content-Length')) {130- this.set('Content-Length', len = Buffer.isBuffer(body)131- ? body.length132- : Buffer.byteLength(body));133- }134-135- // ETag support136- // TODO: W/ support137- if (app.settings.etag && len && ('GET' == req.method || 'HEAD' == req.method)) {138- if (!this.get('ETag')) {139- this.set('ETag', etag(body));140- }141- }142-127 // write strings in utf-8128 if ('string' === typeof body) {129 encoding = 'utf8';130 type = this.get('Content-Type');3 unmodified lines134 this.set('Content-Type', setCharset(type, 'utf-8'));135 }136 }137 138+ // populate Content-Length139+ if (undefined !== body && !this.get('Content-Length')) {140+ len = Buffer.isBuffer(body)141+ ? body.length142+ : Buffer.byteLength(body, encoding);143+ this.set('Content-Length', len);144+ }145+146+ // ETag support147+ var etag = len !== undefined && app.get('etag fn');148+ if (etag && ('GET' === req.method || 'HEAD' === req.method)) {149+ if (!this.get('ETag')) {150+ etag = etag(body, encoding);151+ etag && this.set('ETag', etag);152+ }153+ }154+155 // freshness156 if (req.fresh) this.statusCode = 304;157 158 // strip irrelevant headers661 unmodified linesmodified:lib/utils.js+70 added-3 removed
2 unmodified lines3 */4 5 var mime = require('send').mime;6 var crc32 = require('buffer-crc32');7+var crypto = require('crypto');8 var basename = require('path').basename;9 var deprecate = require('util').deprecate;10 var proxyaddr = require('proxy-addr');11 26 unmodified lines38 return deprecate(fn, msg);39 };40 41 /**41- * Return ETag for `body`.42+ * Return strong ETag for `body`.43 *44 * @param {String|Buffer} body45+ * @param {String} [encoding]46 * @return {String}47 * @api private48 */49 48-exports.etag = function(body){49- return '"' + crc32.signed(body) + '"';50+exports.etag = function etag(body, encoding){51+ if (body.length === 0) {52+ // fast-path empty body53+ return '"1B2M2Y8AsgTpgAmY7PhCfg=="'54+ }55+56+ var hash = crypto57+ .createHash('md5')58+ .update(body, encoding)59+ .digest('base64')60+ return '"' + hash + '"'61 };62 63 /**64+ * Return weak ETag for `body`.65+ *66+ * @param {String|Buffer} body67+ * @param {String} [encoding]68+ * @return {String}69+ * @api private70+ */71+72+exports.wetag = function wetag(body, encoding){73+ if (body.length === 0) {74+ // fast-path empty body75+ return 'W/"0-0"'76+ }77+78+ var buf = Buffer.isBuffer(body)79+ ? body80+ : new Buffer(body, encoding)81+ var len = buf.length82+ return 'W/"' + len.toString(16) + '-' + crc32.unsigned(buf) + '"'83+};84+85+/**86 * Check if `path` looks absolute.87 *88 * @param {String} path89 * @return {Boolean}107 unmodified lines197 return ret;198 }199 200 /**201+ * Compile "etag" value to function.202+ *203+ * @param {Boolean|String|Function} val204+ * @return {Function}205+ * @api private206+ */207+208+exports.compileETag = function(val) {209+ var fn;210+211+ if (typeof val === 'function') {212+ return val;213+ }214+215+ switch (val) {216+ case true:217+ fn = exports.wetag;218+ break;219+ case false:220+ break;221+ case 'strong':222+ fn = exports.etag;223+ break;224+ case 'weak':225+ fn = exports.wetag;226+ break;227+ default:228+ throw new TypeError('unknown value for etag function: ' + val);229+ }230+231+ return fn;232+}233+234+/**235 * Compile "proxy trust" value to function.236 *237 * @param {Boolean|String|Number|Array|Function} val238 * @return {Function}54 unmodified linesmodified:test/acceptance/ejs.js+6 added-9 removed
5 unmodified lines6 describe('GET /', function(){7 it('should respond with html', function(done){8 request(app)9 .get('/')10- .end(function(err, res){11- res.should.have.status(200);12- res.should.have.header('Content-Type', 'text/html; charset=utf-8');13- res.text.should.include('<li>tobi <tobi@learnboost.com></li>');14- res.text.should.include('<li>loki <loki@learnboost.com></li>');15- res.text.should.include('<li>jane <jane@learnboost.com></li>');16- done();17- });10+ .expect('Content-Type', 'text/html; charset=utf-8')11+ .expect(/<li>tobi <tobi@learnboost\.com><\/li>/)12+ .expect(/<li>loki <loki@learnboost\.com><\/li>/)13+ .expect(/<li>jane <jane@learnboost\.com><\/li>/)14+ .expect(200, done)15 })16 })20-})17+})modified:test/acceptance/markdown.js+2 added-2 removed
1 2 var app = require('../../examples/markdown')3- , request = require('supertest');3+var request = require('supertest')4 5 describe('markdown', function(){6 describe('GET /', function(){7 it('should respond with html', function(done){9 unmodified lines17 .get('/fail')18 .expect(500,done)19 })20 })21-})21+})modified:test/acceptance/mvc.js+10 added-17 removed
45 unmodified lines46 describe('GET /users', function(){47 it('should display a list of users', function(done){48 request(app)49 .get('/users')50- .end(function(err, res){51- res.text.should.include('<h1>Users</h1>');52- res.text.should.include('>TJ<');53- res.text.should.include('>Guillermo<');54- res.text.should.include('>Nathan<');55- done();56- })50+ .expect(/<h1>Users<\/h1>/)51+ .expect(/>TJ</)52+ .expect(/>Guillermo</)53+ .expect(/>Nathan</)54+ .expect(200, done)55 })56 })57 58 describe('GET /user/:id', function(){59 describe('when present', function(){60 it('should display the user', function(done){61 request(app)62 .get('/user/0')65- .end(function(err, res){66- res.text.should.include('<h1>TJ <a href="/user/0/edit">edit');67- done();68- })63+ .expect(200, /<h1>TJ <a href="\/user\/0\/edit">edit/, done)64 })65 66 it('should display the users pets', function(done){67 request(app)68 .get('/user/0')74- .end(function(err, res){75- res.text.should.include('/pet/0">Tobi');76- res.text.should.include('/pet/1">Loki');77- res.text.should.include('/pet/2">Jane');78- done();79- })69+ .expect(/\/pet\/0">Tobi/)70+ .expect(/\/pet\/1">Loki/)71+ .expect(/\/pet\/2">Jane/)72+ .expect(200, done)73 })74 })75 76 describe('when not present', function(){46 unmodified linesmodified:test/acceptance/params.js+18 added-2 removed
1 var app = require('../../examples/params/app')2- , request = require('supertest');2+var request = require('supertest')3 4 describe('params', function(){5 describe('GET /', function(){6 it('should respond with instructions', function(done){10 unmodified lines17 .expect(/user tj/,done)18 })19 })20 21+ describe('GET /user/9', function(){22+ it('should fail to find user', function(done){23+ request(app)24+ .get('/user/9')25+ .expect(/failed to find user/,done)26+ })27+ })28+29 describe('GET /users/0-2', function(){30 it('should respond with three users', function(done){31 request(app)32 .get('/users/0-2')33 .expect(/users tj, tobi/,done)34 })35 })36+37+ describe('GET /users/foo-bar', function(){38+ it('should fail integer parsing', function(done){39+ request(app)40+ .get('/users/foo-bar')41+ .expect(/failed to parseInt foo/,done)28-})42+ })43+ })44+})modified:test/acceptance/resource.js+19 added-3 removed
1 var app = require('../../examples/resource/app')2- , request = require('supertest');2+var request = require('supertest')3 4 describe('resource', function(){5 describe('GET /', function(){6 it('should respond with instructions', function(done){18 unmodified lines25 .expect(/^{"name":"ciaran"}/,done)26 })27 })28 29+ describe('GET /users/9', function(){30+ it('should respond with error', function(done){31+ request(app)32+ .get('/users/9')33+ .expect('{"error":"Cannot find user"}', done)34+ })35+ })36+37 describe('GET /users/1..3', function(){38 it('should respond with users 1 through 3', function(done){39 request(app)40 .get('/users/1..3')1 unmodified line42 })43 })44 45 describe('DELETE /users/1', function(){38- it('should respond with users 1 through 3', function(done){46+ it('should delete user 1', function(done){47 request(app)48 .del('/users/1')49 .expect(/^destroyed/,done)50 })51 })52 53+ describe('DELETE /users/9', function(){54+ it('should fail', function(done){55+ request(app)56+ .del('/users/9')57+ .expect('Cannot find user', done)58+ })59+ })60+61 describe('GET /users/1..3.json', function(){62 it('should respond with users 2 and 3 as json', function(done){63 request(app)64 .get('/users/1..3.json')65 .expect(/^\[null,{"name":"aaron"},{"name":"guillermo"}\]/,done)66 })67 })52-})68+})modified:test/acceptance/web-service.js+2 added-6 removed
96 unmodified lines97 describe('when requesting an invalid route', function(){98 it('should respond with 404 json', function(done){99 request(app)100 .get('/api/something?api-key=bar')101- .end(function(err, res){102- res.should.have.status(404);103- res.should.be.json;104- res.text.should.equal('{"error":"Lame, can\'t find that"}');105- done();106- });101+ .expect('Content-Type', /json/)102+ .expect(404, '{"error":"Lame, can\'t find that"}', done)103 })104 })105 })modified:test/app.param.js+18 added
155 unmodified lines156 .get('/foo/bob')157 .expect('2 2 foo,bob', done);158 })159 160+ it('should work with encoded values', function(done){161+ var app = express();162+163+ app.param('name', function(req, res, next, name){164+ req.params.name = name;165+ next();166+ });167+168+ app.get('/user/:name', function(req, res){169+ var name = req.params.name;170+ res.send('' + name);171+ });172+173+ request(app)174+ .get('/user/foo%25bar')175+ .expect('foo%bar', done);176+ })177+178 it('should catch thrown error', function(done){179 var app = express();180 181 app.param('id', function(req, res, next, id){60 unmodified linesmodified:test/app.router.js+24 added
532 unmodified lines533 })534 })535 })536 537+ describe('when next("route") is called', function(){538+ it('should jump to next route', function(done){539+ var app = express()540+541+ function fn(req, res, next){542+ res.set('X-Hit', '1')543+ next('route')544+ }545+546+ app.get('/foo', fn, function(req, res, next){547+ res.end('failure')548+ });549+550+ app.get('/foo', function(req, res){551+ res.end('success')552+ })553+554+ request(app)555+ .get('/foo')556+ .expect('X-Hit', '1')557+ .expect(200, 'success', done)558+ })559+ })560+561 describe('when next(err) is called', function(){562 it('should break out of app.router', function(done){563 var app = express()564 , calls = [];94 unmodified linesmodified:test/config.js+24 added-1 removed
11 unmodified lines12 it('should return the app when undefined', function(){13 var app = express();14 app.set('foo', undefined).should.equal(app);15 })16+17+ describe('"etag"', function(){18+ it('should throw on bad value', function(){19+ var app = express()20+ app.set.bind(app, 'etag', 42).should.throw(/unknown value/)21+ })22+23+ it('should set "etag fn"', function(){24+ var app = express()25+ var fn = function(){}26+ app.set('etag', fn)27+ app.get('etag fn').should.equal(fn)28+ })29+ })30+31+ describe('"trust proxy"', function(){32+ it('should set "trust proxy fn"', function(){33+ var app = express()34+ var fn = function(){}35+ app.set('trust proxy', fn)36+ app.get('trust proxy fn').should.equal(fn)37+ })38+ })39 })40 41 describe('.get()', function(){42 it('should return undefined when unset', function(){70 unmodified lines113 app.set('foo', 'bar');114 app.disabled('foo').should.be.false;115 })116 })94-})117+})modified:test/req.fresh.js+6 added-5 removed
4 unmodified lines5 describe('req', function(){6 describe('.fresh', function(){7 it('should return true when the resource is not modified', function(done){8 var app = express();9+ var etag = '"12345"';10 11 app.use(function(req, res){11- res.set('ETag', '12345');12+ res.set('ETag', etag);13 res.send(req.fresh);14 });15 16 request(app)17 .get('/')17- .set('If-None-Match', '12345')18+ .set('If-None-Match', etag)19 .expect(304, done);20 })21 22 it('should return false when the resource is modified', function(done){23 var app = express();24 25 app.use(function(req, res){25- res.set('ETag', '123');26+ res.set('ETag', '"123"');27 res.send(req.fresh);28 });29 30 request(app)31 .get('/')31- .set('If-None-Match', '12345')32- .expect('false', done);32+ .set('If-None-Match', '"12345"')33+ .expect(200, 'false', done);34 })35 })36 })modified:test/req.stale.js+6 added-5 removed
4 unmodified lines5 describe('req', function(){6 describe('.stale', function(){7 it('should return false when the resource is not modified', function(done){8 var app = express();9+ var etag = '"12345"';10 11 app.use(function(req, res){11- res.set('ETag', '12345');12+ res.set('ETag', etag);13 res.send(req.stale);14 });15 16 request(app)17 .get('/')17- .set('If-None-Match', '12345')18+ .set('If-None-Match', etag)19 .expect(304, done);20 })21 22 it('should return true when the resource is modified', function(done){23 var app = express();24 25 app.use(function(req, res){25- res.set('ETag', '123');26+ res.set('ETag', '"123"');27 res.send(req.stale);28 });29 30 request(app)31 .get('/')31- .set('If-None-Match', '12345')32- .expect('true', done);32+ .set('If-None-Match', '"12345"')33+ .expect(200, 'true', done);34 })35 })36 })modified:test/res.cookie.js+2 added-5 removed
89 unmodified lines90 91 request(app)92 .get('/')93 .end(function(err, res){94- res.headers['set-cookie'][0].should.not.include('Thu, 01 Jan 1970 00:00:01 GMT');94+ res.headers['set-cookie'][0].should.not.containEql('Thu, 01 Jan 1970 00:00:01 GMT');95 done();96 })97 })98 6 unmodified lines105 });106 107 request(app)108 .get('/')109- .end(function(err, res){110- res.headers['set-cookie'][0].should.include('Max-Age=1');111- done();112- })109+ .expect('Set-Cookie', /Max-Age=1/, done)110 })111 112 it('should not mutate the options object', function(done){113 var app = express();60 unmodified linesmodified:test/res.download.js+16 added-19 removed
12 unmodified lines13 });14 15 request(app)16 .get('/')17- .end(function(err, res){18- res.should.have.header('Content-Type', 'text/html; charset=UTF-8');19- res.should.have.header('Content-Disposition', 'attachment; filename="user.html"');20- res.text.should.equal('<p>{{user.name}}</p>');21- done();22- });17+ .expect('Content-Type', 'text/html; charset=UTF-8')18+ .expect('Content-Disposition', 'attachment; filename="user.html"')19+ .expect(200, '<p>{{user.name}}</p>', done)20 })21 })22 23 describe('.download(path, filename)', function(){5 unmodified lines29 });30 31 request(app)32 .get('/')36- .end(function(err, res){37- res.should.have.header('Content-Type', 'text/html; charset=UTF-8');38- res.should.have.header('Content-Disposition', 'attachment; filename="document"');39- done();40- });33+ .expect('Content-Type', 'text/html; charset=UTF-8')34+ .expect('Content-Disposition', 'attachment; filename="document"')35+ .expect(200, done)36 })37 })38 39 describe('.download(path, fn)', function(){6 unmodified lines46 });47 48 request(app)49 .get('/')55- .end(function(err, res){56- res.should.have.header('Content-Type', 'text/html; charset=UTF-8');57- res.should.have.header('Content-Disposition', 'attachment; filename="user.html"');58- });50+ .expect('Content-Type', 'text/html; charset=UTF-8')51+ .expect('Content-Disposition', 'attachment; filename="user.html"')52+ .expect(200, function(err){53+ assert.ifError(err)54+ })55 })56 })57 58 describe('.download(path, filename, fn)', function(){6 unmodified lines65 });66 67 request(app)68 .get('/')73- .end(function(err, res){74- res.should.have.header('Content-Type', 'text/html; charset=UTF-8');75- res.should.have.header('Content-Disposition', 'attachment; filename="document"');76- });69+ .expect('Content-Type', 'text/html; charset=UTF-8')70+ .expect('Content-Disposition', 'attachment; filename="document"')71+ .expect(200, function(err){72+ assert.ifError(err)73+ })74 })75 })76 77 describe('on failure', function(){38 unmodified linesmodified:test/res.redirect.js+6 added-10 removed
11 unmodified lines12 });13 14 request(app)15 .get('/')16- .end(function(err, res){17- res.statusCode.should.equal(302);18- res.headers.should.have.property('location', 'http://google.com');19- done();20- })16+ .expect('location', 'http://google.com')17+ .expect(302, done)18 })19 })20 21 describe('.redirect(status, url)', function(){133 unmodified lines155 156 request(app)157 .get('/')158 .set('Accept', 'application/octet-stream')162- .end(function(err, res){163- res.should.have.status(302);164- res.headers.should.have.property('location', 'http://google.com');159+ .expect('location', 'http://google.com')160+ .expect('content-length', '0')161+ .expect(302, '', function(err, res){162+ if (err) return done(err)163 res.headers.should.not.have.property('content-type');166- res.headers.should.have.property('content-length', '0');167- res.text.should.equal('');164 done();165 })166 })167 })1 unmodified linemodified:test/res.send.js+134 added-20 removed
107 unmodified lines108 });109 110 request(app)111 .get('/')112- .expect('ETag', '"-1498647312"')112+ .expect('ETag', 'W/"7ff-2796319984"')113 .end(done);114 })115 116 it('should not set ETag for non-GET/HEAD', function(done){80 unmodified lines197 });198 199 request(app)200 .get('/')201- .expect('ETag', '"-1498647312"')201+ .expect('ETag', 'W/"7ff-2796319984"')202 .end(done);203 })204 205 it('should not override Content-Type', function(done){84 unmodified lines290 })291 292 it('should always check regardless of length', function(done){293 var app = express();294+ var etag = '"asdf"';295 296 app.use(function(req, res, next){296- res.set('ETag', 'asdf');297+ res.set('ETag', etag);298 res.send('hey');299 });300 301 request(app)302 .get('/')302- .set('If-None-Match', 'asdf')303+ .set('If-None-Match', etag)304 .expect(304, done);305 })306 307 it('should respond with 304 Not Modified when fresh', function(done){5 unmodified lines313 });314 315 request(app)316 .get('/')316- .set('If-None-Match', '"-1498647312"')317+ .set('If-None-Match', 'W/"7ff-2796319984"')318 .expect(304, done);319 })320 321 it('should not perform freshness check unless 2xx or 304', function(done){322 var app = express();323+ var etag = '"asdf"';324 325 app.use(function(req, res, next){326 res.status(500);325- res.set('ETag', 'asdf');327+ res.set('ETag', etag);328 res.send('hey');329 });330 331 request(app)332 .get('/')331- .set('If-None-Match', 'asdf')333+ .set('If-None-Match', etag)334 .expect('hey')335 .expect(500, done);336 })337 10 unmodified lines348 })349 350 describe('"etag" setting', function(){351 describe('when enabled', function(){350- it('should send ETag even when content-length < 1024', function(done){352+ it('should send ETag', function(done){353 var app = express();354 355 app.use(function(req, res){356 res.send('kajdslfkasdf');357 });358 359+ app.enable('etag');360+361 request(app)362 .get('/')359- .end(function(err, res){360- res.headers.should.have.property('etag');361- done();363+ .expect('etag', 'W/"c-1525560792"', done)364+ })365+366+ it('should send ETag for empty string response', function(done){367+ var app = express()368+369+ app.use(function(req, res){370+ res.send('')371 });372+373+ app.enable('etag')374+375+ request(app)376+ .get('/')377+ .expect('etag', 'W/"0-0"', done)378 })379 365- it('should send ETag ', function(done){380+ it('should send ETag for long response', function(done){381 var app = express();382 383 app.use(function(req, res){384 var str = Array(1024 * 2).join('-');385 res.send(str);386 });387 388+ app.enable('etag');389+390 request(app)391 .get('/')375- .end(function(err, res){376- res.headers.should.have.property('etag', '"-1498647312"');377- done();392+ .expect('etag', 'W/"7ff-2796319984"', done)393+ });394+395+ it('should not override ETag when manually set', function(done){396+ var app = express();397+398+ app.use(function(req, res){399+ res.set('etag', '"asdf"');400+ res.send(200);401 });402+403+ app.enable('etag');404+405+ request(app)406+ .get('/')407+ .expect('etag', '"asdf"', done)408 });409+410+ it('should not send ETag for res.send()', function(done){411+ var app = express()412+413+ app.use(function(req, res){414+ res.send()415+ });416+417+ app.enable('etag')418+419+ request(app)420+ .get('/')421+ .end(function(err, res){422+ res.headers.should.not.have.property('etag');423+ done();424+ })425+ })426 });427 428 describe('when disabled', function(){429 it('should send no ETag', function(done){19 unmodified lines449 450 app.disable('etag');451 452 app.use(function(req, res){407- res.set('etag', 1);453+ res.set('etag', '"asdf"');454 res.send(200);455 });456 457 request(app)458 .get('/')413- .end(function(err, res){414- res.headers.should.have.property('etag');415- done();416- });459+ .expect('etag', '"asdf"', done)460 });461 });462+463+ describe('when "strong"', function(){464+ it('should send strong ETag', function(done){465+ var app = express()466+467+ app.set('etag', 'strong');468+469+ app.use(function(req, res){470+ res.send('hello, world!');471+ });472+473+ request(app)474+ .get('/')475+ .expect('etag', '"Otu60XkfuuPskIiUxJY4cA=="', done)476+ })477+ })478+479+ describe('when "weak"', function(){480+ it('should send weak ETag', function(done){481+ var app = express()482+483+ app.set('etag', 'weak');484+485+ app.use(function(req, res){486+ res.send('hello, world!');487+ });488+489+ request(app)490+ .get('/')491+ .expect('etag', 'W/"d-1486392595"', done)492+ })493+ })494+495+ describe('when a function', function(){496+ it('should send custom ETag', function(done){497+ var app = express()498+499+ app.set('etag', function(body, encoding){500+ body.should.equal('hello, world!')501+ encoding.should.equal('utf8')502+ return '"custom"'503+ });504+505+ app.use(function(req, res){506+ res.send('hello, world!');507+ });508+509+ request(app)510+ .get('/')511+ .expect('etag', '"custom"', done)512+ })513+514+ it('should not send falsy ETag', function(done){515+ var app = express()516+517+ app.set('etag', function(body, encoding){518+ return undefined519+ });520+521+ app.use(function(req, res){522+ res.send('hello, world!');523+ });524+525+ request(app)526+ .get('/')527+ .end(function(err, res){528+ res.headers.should.not.have.property('etag')529+ done();530+ })531+ })532+ })533 })534 })modified:test/res.sendfile.js+1 added-5 removed
7 unmodified lines8 it('should invoke the callback when complete', function(done){9 var app = express();10 11 app.use(function(req, res){12- res.sendfile('test/fixtures/user.html', function(err){13- assert(!err);14- req.socket.listeners('error').should.have.length(1); // node's original handler15- done();16- });12+ res.sendfile('test/fixtures/user.html', done)13 });14 15 request(app)16 .get('/')246 unmodified linesmodified:test/res.set.js+7 added-6 removed
18 unmodified lines19 })20 21 it('should coerce to a string', function(){22 res.headers = {};23- res.set('ETag', 123);24- res.get('ETag').should.equal('123');23+ res.set('X-Number', 123);24+ res.get('X-Number').should.equal('123');25 })26 })27 28 describe('.set(field, values)', function(){11 unmodified lines40 })41 42 it('should coerce to an array of strings', function(){43 res.headers = {};44- res.set('ETag', [123, 456]);45- JSON.stringify(res.get('ETag')).should.equal('["123","456"]');44+ res.set('X-Numbers', [123, 456]);45+ JSON.stringify(res.get('X-Numbers'))46+ .should.equal('["123","456"]');47 })48 49 it('should not set a charset of one is already set', function () {50 res.headers = {};21 unmodified lines72 })73 74 it('should coerce to a string', function(){75 res.headers = {};75- res.set({ ETag: 123 });76- res.get('ETag').should.equal('123');76+ res.set({ 'X-Number': 123 });77+ res.get('X-Number').should.equal('123');78 })79 })80 })modified:test/utils.js+60 added-8 removed
1 2 var utils = require('../lib/utils')3 , assert = require('assert');4 5-describe('utils.etag(body)', function(){5+describe('utils.deprecate(fn, msg)', function(){6+ var env7+ before(function(){8+ env = process.env.NODE_ENV9+ })10+ after(function(){11+ process.env.NODE_ENV = env12+ })13 7- var str = 'Hello CRC';8- var strUTF8 = '<!DOCTYPE html>\n<html>\n<head>\n</head>\n<body><p>自動販売</p></body></html>';14+ it('should pass-through fn in test environment', function(){15+ var fn = function(){}16+ process.env.NODE_ENV = 'test'17+ utils.deprecate(fn).should.equal(fn)18+ })19 20+ it('should return new fn in other environment', function(){21+ var fn = function(){}22+ process.env.NODE_ENV = ''23+ utils.deprecate(fn).should.not.equal(fn)24+ })25+})26+27+describe('utils.etag(body, encoding)', function(){28 it('should support strings', function(){11- utils.etag(str).should.eql('"-2034458343"');29+ utils.etag('express!')30+ .should.eql('"zZdv4imtWD49AHEviejT6A=="')31 })32 33 it('should support utf8 strings', function(){15- utils.etag(strUTF8).should.eql('"1395090196"');34+ utils.etag('express❤', 'utf8')35+ .should.eql('"fsFba4IxwQS6h6Umb+FNxw=="')36 })37 38 it('should support buffer', function(){19- utils.etag(new Buffer(strUTF8)).should.eql('"1395090196"');20- utils.etag(new Buffer(str)).should.eql('"-2034458343"');39+ var buf = new Buffer('express!')40+ utils.etag(buf)41+ .should.eql('"zZdv4imtWD49AHEviejT6A=="');42 })43 44+ it('should support empty string', function(){45+ utils.etag('')46+ .should.eql('"1B2M2Y8AsgTpgAmY7PhCfg=="');47+ })48 })49 50+describe('utils.wetag(body, encoding)', function(){51+ it('should support strings', function(){52+ utils.wetag('express!')53+ .should.eql('W/"8-3098196679"')54+ })55+56+ it('should support utf8 strings', function(){57+ utils.wetag('express❤', 'utf8')58+ .should.eql('W/"a-1751845617"')59+ })60+61+ it('should support buffer', function(){62+ var buf = new Buffer('express!')63+ utils.wetag(buf)64+ .should.eql('W/"8-3098196679"');65+ })66+67+ it('should support empty string', function(){68+ utils.wetag('')69+ .should.eql('W/"0-0"');70+ })71+})72+73 describe('utils.isAbsolute()', function(){74 it('should support windows', function(){75 assert(utils.isAbsolute('c:\\'));76 assert(!utils.isAbsolute(':\\'));77 })78 31- it('should unices', function(){79+ it('should support windows unc', function(){80+ assert(utils.isAbsolute('\\\\foo\\bar'))81+ })82+83+ it('should support unices', function(){84 assert(utils.isAbsolute('/foo/bar'));85 assert(!utils.isAbsolute('foo/bar'));86 })87 })8 unmodified linesmodified:History.md+35 added
1+unreleased2+==========3+4+ * custom etag control with `app.set('etag', val)`5+ - `app.set('etag', function(body, encoding){ return '"etag"' })` custom etag generation6+ - `app.set('etag', 'weak')` weak tag7+ - `app.set('etag', 'strong')` strong etag8+ - `app.set('etag', false)` turn off9+ - `app.set('etag', true)` standard etag10+ * mark `res.send` ETag as weak and reduce collisions11+ * update send to 0.4.012+ - Calculate ETag with md5 for reduced collisions13+ - Ignore stream errors after request ends14+ - deps: debug@0.8.115+16 4.3.2 / 2014-05-2817 ==================18 19 * fix handling of errors from `router.param()` callbacks118 unmodified lines138 - `app.router()` - returns the app Router instance139 - `app.route()` - Proxy to the app's `Router#route()` method to create a new route140 - Router & Route - public API141 142+3.9.0 / 2014-05-30143+==================144+145+ * custom etag control with `app.set('etag', val)`146+ - `app.set('etag', function(body, encoding){ return '"etag"' })` custom etag generation147+ - `app.set('etag', 'weak')` weak tag148+ - `app.set('etag', 'strong')` strong etag149+ - `app.set('etag', false)` turn off150+ - `app.set('etag', true)` standard etag151+ * Include ETag in HEAD requests152+ * mark `res.send` ETag as weak and reduce collisions153+ * update connect to 2.18.0154+ - deps: compression@1.0.3155+ - deps: serve-index@1.1.0156+ - deps: serve-static@1.2.0157+ * update send to 0.4.0158+ - Calculate ETag with md5 for reduced collisions159+ - Ignore stream errors after request ends160+ - deps: debug@0.8.1161+162 3.8.1 / 2014-05-27163 ==================164 165 * update connect to 2.17.31354 unmodified linesmodified:package.json+5 added-5 removed
46 unmodified lines47 "repository": "git://github.com/visionmedia/express",48 "license": "MIT",49 "dependencies": {50 "accepts": "1.0.1",51+ "buffer-crc32": "0.2.1",52 "parseurl": "1.0.1",53 "proxy-addr": "1.0.0",54 "range-parser": "1.0.0",55+ "send": "0.4.0",56 "type-is": "1.2.0",57 "cookie": "0.1.2",56- "buffer-crc32": "0.2.1",58 "fresh": "0.2.2",59 "methods": "1.0.0",59- "send": "0.3.0",60 "cookie-signature": "1.0.3",61 "merge-descriptors": "0.0.2",62 "utils-merge": "1.0.0",63 "escape-html": "1.0.1",4 unmodified lines68 },69 "devDependencies": {70 "after": "0.8.1",71 "istanbul": "0.2.10",72- "mocha": "~1.19.0",73- "should": "~3.3.1",72+ "mocha": "~1.20.0",73+ "should": "~4.0.0",74 "supertest": "~0.12.0",75 "connect-redis": "~2.0.0",76 "ejs": "~1.0.0",77- "jade": "~0.35.0",77+ "jade": "~1.3.1",78 "marked": "0.3.2",79 "multiparty": "~3.2.4",80 "hjs": "~0.0.6",81 "body-parser": "1.2.2",16 unmodified lines