Merge tag '4.15.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 c8d9223, 504a51c · Browse files · 30 files·+867 added−331 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
30 files+867 added−331 removed
- tests:+345 added−124 removed
- other:+522 added−207 removed
Provenance
- Commit
501e24e- Tree
2190f59- Author
Douglas Christopher Wilson <doug@somethingdoug.com>- Committer
Douglas Christopher Wilson <doug@somethingdoug.com>- Parent 1
c8d9223- Parent 2
504a51c
30 files changed+867 added−331 removed
modified:examples/auth/index.js+3 added-3 removed
1234566789101132 unmodified lines444546474848495051529 unmodified lines6263646566666768697060 unmodified lines/** * Module dependencies. */
var express = require('../..');var hash = require('./pass').hash;var bodyParser = require('body-parser');var hash = require('pbkdf2-password')()var session = require('express-session');
var app = module.exports = express();
32 unmodified lines
// when you create a user, generate a salt// and hash the password ('foobar' is the pass here)
hash('foobar', function(err, salt, hash){hash({ password: 'foobar' }, function (err, pass, salt, hash) { if (err) throw err; // store the salt & hash in the "db" users.tj.salt = salt; users.tj.hash = hash;9 unmodified lines if (!user) return fn(new Error('cannot find user')); // apply the same algorithm to the POSTed password, applying // the hash against the pass / salt, if there is a match we // found the user hash(pass, user.salt, function(err, hash){ hash({ password: pass, salt: user.salt }, function (err, pass, salt, hash) { if (err) return fn(err); if (hash == user.hash) return fn(null, user); fn(new Error('invalid password')); });60 unmodified linesdeleted:examples/auth/pass.js-48 removed
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
// check out https://github.com/tj/node-pwd
/** * Module dependencies. */
var crypto = require('crypto');
/** * Bytesize. */
var len = 128;
/** * Iterations. ~300ms */
var iterations = 12000;
/** * Hashes a password with optional `salt`, otherwise * generate a salt for `pass` and invoke `fn(err, salt, hash)`. * * @param {String} password to hash * @param {String} optional salt * @param {Function} callback * @api public */
exports.hash = function (pwd, salt, fn) { if (3 == arguments.length) { crypto.pbkdf2(pwd, salt, iterations, len, function(err, hash){ fn(err, hash.toString('base64')); }); } else { fn = salt; crypto.randomBytes(len, function(err, salt){ if (err) return fn(err); salt = salt.toString('base64'); crypto.pbkdf2(pwd, salt, iterations, len, function(err, hash){ if (err) return fn(err); fn(null, salt, hash.toString('base64')); }); }); }};modified:examples/error-pages/index.js+11 added-14 removed
58 unmodified lines59 60 app.use(function(req, res, next){61 res.status(404);62 63- // respond with html page64- if (req.accepts('html')) {65- res.render('404', { url: req.url });66- return;67- }68-69- // respond with json70- if (req.accepts('json')) {71- res.send({ error: 'Not found' });72- return;73- }74-75- // default to plain-text. send()76- res.type('txt').send('Not found');63+ res.format({64+ html: function () {65+ res.render('404', { url: req.url })66+ },67+ json: function () {68+ res.json({ error: 'Not found' })69+ },70+ default: function () {71+ res.type('txt').send('Not found')72+ }73+ })74 });75 76 // error-handling middleware, take the same form77 // as regular middleware, however they require an23 unmodified linesdeleted:examples/expose-data-to-client/views/page.jade-14 removed
1-html2- head3- title Express4- script.5- // call this whatever you like,6- // or dump them into individual7- // props like "var user ="8- var data = !{JSON.stringify(expose)}9- body10- h1 Expose client data11- p The following was exposed to the client:12- pre13- script.14- document.write(JSON.stringify(data, null, 2))deleted:examples/expose-data-to-client/index.js-64 removed
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
var express = require('../..');var logger = require('morgan');var app = express();
app.set('view engine', 'jade');app.set('views', __dirname + '/views');
function User(name) { this.private = 'heyyyy'; this.secret = 'something'; this.name = name; this.id = 123;}
// You'll probably want to do// something like this so you// dont expose "secret" data.
User.prototype.toJSON = function(){ return { id: this.id, name: this.name };};
app.use(logger('dev'));
// earlier on expose an object// that we can tack properties on.// all res.locals props are exposed// to the templates, so "expose" will// be present.
app.use(function(req, res, next){ res.locals.expose = {}; // you could alias this as req or res.expose // to make it shorter and less annoying next();});
// pretend we loaded a user
app.use(function(req, res, next){ req.user = new User('Tobi'); next();});
app.get('/', function(req, res){ res.redirect('/user');});
app.get('/user', function(req, res){ // we only want to expose the user // to the client for this route: res.locals.expose.user = req.user; res.render('page');});
/* istanbul ignore next */if (!module.parent) { app.listen(3000); console.log('Express started on port 3000');}modified:lib/application.js+9 added-8 removed
23 unmodified lines24 var flatten = require('array-flatten');25 var merge = require('utils-merge');26 var resolve = require('path').resolve;27 var Router = require('router');28+var setPrototyeOf = require('setprototypeof')29 var slice = Array.prototype.slice;30 31 /**32 * Application prototype.76 unmodified lines109 delete this.settings['trust proxy fn'];110 }111 112 // inherit protos112- this.request.__proto__ = parent.request;113- this.response.__proto__ = parent.response;114- this.engines.__proto__ = parent.engines;115- this.settings.__proto__ = parent.settings;113+ setPrototyeOf(this.request, parent.request)114+ setPrototyeOf(this.response, parent.response)115+ setPrototyeOf(this.engines, parent.engines)116+ setPrototyeOf(this.settings, parent.settings)117 });118 119 // setup locals120 this.locals = Object.create(null);39 unmodified lines160 req.res = res;161 res.req = req;162 163 // alter the prototypes163- req.__proto__ = this.request;164- res.__proto__ = this.response;164+ setPrototyeOf(req, this.request)165+ setPrototyeOf(res, this.response)166 167 // setup locals168 if (!res.locals) {169 res.locals = Object.create(null);54 unmodified lines224 // restore .app property on req and res225 router.use(path, function mounted_app(req, res, next) {226 var orig = req.app;227 fn.handle(req, res, function (err) {227- req.__proto__ = orig.request;228- res.__proto__ = orig.response;228+ setPrototyeOf(req, orig.request)229+ setPrototyeOf(res, orig.response)230 next(err);231 });232 });233 397 unmodified linesmodified:lib/express.js+10 added-2 removed
38 unmodified lines39 40 mixin(app, EventEmitter.prototype, false);41 mixin(app, proto, false);42 43- app.request = { __proto__: req, app: app };44- app.response = { __proto__: res, app: app };43+ // expose the prototype that will get set on requests44+ app.request = Object.create(req, {45+ app: { configurable: true, enumerable: true, writable: true, value: app }46+ })47+48+ // expose the prototype that will get set on responses49+ app.response = Object.create(res, {50+ app: { configurable: true, enumerable: true, writable: true, value: app }51+ })52+53 app.init();54 return app;55 }56 54 unmodified linesmodified:lib/request.js+23 added-8 removed
22 unmodified lines23 var proxyaddr = require('proxy-addr');24 25 /**26 * Request prototype.27+ * @public28 */29 29-var req = exports = module.exports = {30- __proto__: http.IncomingMessage.prototype31-};30+var req = Object.create(http.IncomingMessage.prototype)31 32 /**33+ * Module exports.34+ * @public35+ */36+37+module.exports = req38+39+/**40 * Return request header.41 *42 * The `Referrer` header field is special-cased,43 * both `Referrer` and `Referer` are interchangeable.296 unmodified lines340 341 defineGetter(req, 'ips', function ips() {342 var trust = this.app.get('trust proxy fn');343 var addrs = proxyaddr.all(this, trust);338- return addrs.slice(1).reverse();344+345+ // reverse the order (to farthest -> closest)346+ // and remove socket address347+ addrs.reverse().pop()348+349+ return addrs350 });351 352 /**353 * Return subdomains as an array.93 unmodified lines447 */448 449 defineGetter(req, 'fresh', function(){450 var method = this.method;440- var s = this.res.statusCode;451+ var res = this.res452+ var status = res.statusCode453 454 // GET or HEAD for weak freshness validation only455 if ('GET' !== method && 'HEAD' !== method) return false;456 457 // 2xx or 304 as per rfc2616 14.26446- if ((s >= 200 && s < 300) || 304 === s) {447- return fresh(this.headers, (this.res._headers || {}));458+ if ((status >= 200 && status < 300) || 304 === status) {459+ return fresh(this.headers, {460+ 'etag': res.get('ETag'),461+ 'last-modified': res.get('Last-Modified')462+ })463 }464 465 return false;466 });36 unmodified lines503 configurable: true,504 enumerable: true,505 get: getter506 });492-};507+}modified:lib/response.js+13 added-7 removed
18 unmodified lines19 var http = require('http');20 var onFinished = require('on-finished');21 var path = require('path');22 var pathIsAbsolute = require('path-is-absolute');23+var statuses = require('statuses')24 var merge = require('utils-merge');25 var sign = require('cookie-signature').sign;26 var normalizeType = require('./utils').normalizeType;27 var normalizeTypes = require('./utils').normalizeTypes;28 var setCharset = require('./utils').setCharset;28-var statusCodes = http.STATUS_CODES;29 var cookie = require('cookie');30 var send = require('send');31 var extname = path.extname;32 var mime = send.mime;1 unmodified line34 var vary = require('vary');35 36 /**37 * Response prototype.38+ * @public39 */40 40-var res = module.exports = {41- __proto__: http.ServerResponse.prototype42-};41+var res = Object.create(http.ServerResponse.prototype)42 43 /**44+ * Module exports.45+ * @public46+ */47+48+module.exports = res49+50+/**51 * Module variables.52 * @private53 */54 236 unmodified lines291 * @public292 */293 294 res.sendStatus = function sendStatus(statusCode) {289- var body = statusCodes[statusCode] || String(statusCode);295+ var body = statuses[statusCode] || String(statusCode)296 297 this.statusCode = statusCode;298 this.type('txt');299 461 unmodified lines761 762 // Support text/{plain,html} by default763 this.format({764 text: function(){759- body = statusCodes[status] + '. Redirecting to ' + address;765+ body = statuses[status] + '. Redirecting to ' + address766 },767 768 html: function(){769 var u = escapeHtml(address);764- body = '<p>' + statusCodes[status] + '. Redirecting to <a href="' + u + '">' + u + '</a></p>';770+ body = '<p>' + statuses[status] + '. Redirecting to <a href="' + u + '">' + u + '</a></p>'771 },772 773 default: function(){774 body = '';171 unmodified linesmodified:lib/view.js+3 added-1 removed
73 unmodified lines74 }75 76 if (!opts.engines[this.ext]) {77 // load engine78+ var mod = this.ext.substr(1)79+ debug('require "%s"', mod)78- opts.engines[this.ext] = require(this.ext.substr(1)).__express;80+ opts.engines[this.ext] = require(mod).__express81 }82 83 // store loaded engine84 this.engine = opts.engines[this.ext];114 unmodified linesmodified:test/app.router.js+57 added-2 removed
75 unmodified lines76 });77 78 request(app)79 .get('/')80- .expect(404, 'Cannot GET /\n', cb);80+ .expect(404, cb)81 82 request(app)83 .delete('/')84 .expect(200, 'deleted everything', cb);4 unmodified lines89 .expect(200, 'deleted everything', cb);90 });91 })92 93- describe('decode querystring', function(){93+ describe('decode params', function () {94 it('should decode correct params', function(done){95 var app = express();96 97 app.get('/:name', function(req, res, next){464 unmodified lines562 .expect('users from 1 to 50', done);563 })564 565 describe('*', function(){566+ it('should capture everything', function (done) {567+ var app = express()568+569+ app.get('*', function (req, res) {570+ res.end(req.params[0])571+ })572+573+ request(app)574+ .get('/user/tobi.json')575+ .expect('/user/tobi.json', done)576+ })577+578+ it('should decore the capture', function (done) {579+ var app = express()580+581+ app.get('*', function (req, res) {582+ res.end(req.params[0])583+ })584+585+ request(app)586+ .get('/user/tobi%20and%20loki.json')587+ .expect('/user/tobi and loki.json', done)588+ })589+590 it('should denote a greedy capture group', function(done){591 var app = express();592 593 app.get('/user/*.json', function(req, res){337 unmodified lines931 .expect(200, 'success', done)932 })933 })934 935+ describe('when next("router") is called', function () {936+ it('should jump out of router', function (done) {937+ var app = express()938+ var router = express.Router()939+940+ function fn (req, res, next) {941+ res.set('X-Hit', '1')942+ next('router')943+ }944+945+ router.get('/foo', fn, function (req, res, next) {946+ res.end('failure')947+ })948+949+ router.get('/foo', function (req, res, next) {950+ res.end('failure')951+ })952+953+ app.use(router)954+955+ app.get('/foo', function (req, res) {956+ res.end('success')957+ })958+959+ request(app)960+ .get('/foo')961+ .expect('X-Hit', '1')962+ .expect(200, 'success', done)963+ })964+ })965+966 describe('when next(err) is called', function(){967 it('should break out of app.router', function(done){968 var app = express()969 , calls = [];120 unmodified linesmodified:test/req.fresh.js+1 added-1 removed
34 unmodified lines35 36 it('should return false without response headers', function(done){37 var app = express();38 39+ app.disable('x-powered-by')40 app.use(function(req, res){40- res._headers = null;41 res.send(req.fresh);42 });43 44 request(app)5 unmodified linesmodified:test/req.ip.js+2 added-2 removed
77 unmodified lines78 app.use(function(req, res, next){79 res.send(req.ip);80 });81 82- var test = request(app).get('/')83- test.expect(200, getExpectedClientAddress(test._server), done);82+ var test = request(app).get('/')83+ test.expect(200, getExpectedClientAddress(test._server), done)84 })85 })86 })87 })10 unmodified linesmodified:test/req.is.js+133 added-68 removed
1 2-var express = require('../')3- , request = require('supertest');2+var express = require('..')3+var request = require('supertest')4 5-function req(ct) {6- var req = {7- headers: {8- 'content-type': ct,9- 'transfer-encoding': 'chunked'10- },11- __proto__: express.request12- };5+describe('req.is()', function () {6+ describe('when given a mime type', function () {7+ it('should return the type when matching', function (done) {8+ var app = express()9 14- return req;15-}10+ app.use(function (req, res) {11+ res.json(req.is('application/json'))12+ })13 17-describe('req.is()', function(){18- it('should ignore charset', function(){19- req('application/json')20- .is('json')21- .should.equal('json');14+ request(app)15+ .post('/')16+ .type('application/json')17+ .send('{}')18+ .expect(200, '"application/json"', done)19+ })20+21+ it('should return false when not matching', function (done) {22+ var app = express()23+24+ app.use(function (req, res) {25+ res.json(req.is('image/jpeg'))26+ })27+28+ request(app)29+ .post('/')30+ .type('application/json')31+ .send('{}')32+ .expect(200, 'false', done)33+ })34+35+ it('should ignore charset', function (done) {36+ var app = express()37+38+ app.use(function (req, res) {39+ res.json(req.is('application/json'))40+ })41+42+ request(app)43+ .post('/')44+ .type('application/json; charset=UTF-8')45+ .send('{}')46+ .expect(200, '"application/json"', done)47+ })48 })49 50 describe('when content-type is not present', function(){25- it('should return false', function(){26- req('')27- .is('json')28- .should.be.false;51+ it('should return false', function (done) {52+ var app = express()53+54+ app.use(function (req, res) {55+ res.json(req.is('application/json'))56+ })57+58+ request(app)59+ .post('/')60+ .send('{}')61+ .expect(200, 'false', done)62 })63 })64 65 describe('when given an extension', function(){33- it('should lookup the mime type', function(){34- req('application/json')35- .is('json')36- .should.equal('json');66+ it('should lookup the mime type', function (done) {67+ var app = express()68 38- req('text/html')39- .is('json')40- .should.be.false;69+ app.use(function (req, res) {70+ res.json(req.is('json'))71+ })72+73+ request(app)74+ .post('/')75+ .type('application/json')76+ .send('{}')77+ .expect(200, '"json"', done)78 })79 })80 44- describe('when given a mime type', function(){45- it('should match', function(){46- req('application/json')47- .is('application/json')48- .should.equal('application/json');81+ describe('when given */subtype', function(){82+ it('should return the full type when matching', function (done) {83+ var app = express()84 50- req('image/jpeg')51- .is('application/json')52- .should.be.false;85+ app.use(function (req, res) {86+ res.json(req.is('*/json'))87+ })88+89+ request(app)90+ .post('/')91+ .type('application/json')92+ .send('{}')93+ .expect(200, '"application/json"', done)94 })54- })95 56- describe('when given */subtype', function(){57- it('should match', function(){58- req('application/json')59- .is('*/json')60- .should.equal('application/json');96+ it('should return false when not matching', function (done) {97+ var app = express()98 62- req('image/jpeg')63- .is('*/json')64- .should.be.false;99+ app.use(function (req, res) {100+ res.json(req.is('*/html'))101+ })102+103+ request(app)104+ .post('/')105+ .type('application/json')106+ .send('{}')107+ .expect(200, 'false', done)108 })109 67- describe('with a charset', function(){68- it('should match', function(){69- req('text/html; charset=utf-8')70- .is('*/html')71- .should.equal('text/html');110+ it('should ignore charset', function (done) {111+ var app = express()112 73- req('text/plain; charset=utf-8')74- .is('*/html')75- .should.be.false;113+ app.use(function (req, res) {114+ res.json(req.is('*/json'))115 })116+117+ request(app)118+ .post('/')119+ .type('application/json; charset=UTF-8')120+ .send('{}')121+ .expect(200, '"application/json"', done)122 })123 })124 125 describe('when given type/*', function(){81- it('should match', function(){82- req('image/png')83- .is('image/*')84- .should.equal('image/png');126+ it('should return the full type when matching', function (done) {127+ var app = express()128 86- req('text/html')87- .is('image/*')88- .should.be.false;129+ app.use(function (req, res) {130+ res.json(req.is('application/*'))131+ })132+133+ request(app)134+ .post('/')135+ .type('application/json')136+ .send('{}')137+ .expect(200, '"application/json"', done)138 })139 91- describe('with a charset', function(){92- it('should match', function(){93- req('text/html; charset=utf-8')94- .is('text/*')95- .should.equal('text/html');140+ it('should return false when not matching', function (done) {141+ var app = express()142 97- req('something/html; charset=utf-8')98- .is('text/*')99- .should.be.false;143+ app.use(function (req, res) {144+ res.json(req.is('text/*'))145 })146+147+ request(app)148+ .post('/')149+ .type('application/json')150+ .send('{}')151+ .expect(200, 'false', done)152 })153+154+ it('should ignore charset', function (done) {155+ var app = express()156+157+ app.use(function (req, res) {158+ res.json(req.is('application/*'))159+ })160+161+ request(app)162+ .post('/')163+ .type('application/json; charset=UTF-8')164+ .send('{}')165+ .expect(200, '"application/json"', done)166+ })167 })168 })modified:test/req.range.js+83 added-27 removed
1 2 var assert = require('assert');3 var express = require('..');4+var request = require('supertest')5 5-function req(ret) {6- return {7- get: function(){ return ret }8- , __proto__: express.request9- };10-}11-6 describe('req', function(){7 describe('.range(size)', function(){14- it('should return parsed ranges', function(){15- var ranges = [{ start: 0, end: 50 }, { start: 51, end: 100 }]16- ranges.type = 'bytes'17- assert.deepEqual(req('bytes=0-50,51-100').range(120), ranges)8+ it('should return parsed ranges', function (done) {9+ var app = express()10+11+ app.use(function (req, res) {12+ res.json(req.range(120))13+ })14+15+ request(app)16+ .get('/')17+ .set('Range', 'bytes=0-50,51-100')18+ .expect(200, '[{"start":0,"end":50},{"start":51,"end":100}]', done)19 })20 20- it('should cap to the given size', function(){21- var ret = [{ start: 0, end: 74 }];22- ret.type = 'bytes';23- req('bytes=0-100').range(75).should.eql(ret);21+ it('should cap to the given size', function (done) {22+ var app = express()23+24+ app.use(function (req, res) {25+ res.json(req.range(75))26+ })27+28+ request(app)29+ .get('/')30+ .set('Range', 'bytes=0-100')31+ .expect(200, '[{"start":0,"end":74}]', done)32 })33 26- it('should have a .type', function(){27- var ret = [{ start: 0, end: Infinity }];28- ret.type = 'users';29- req('users=0-').range(Infinity).should.eql(ret);34+ it('should cap to the given size when open-ended', function (done) {35+ var app = express()36+37+ app.use(function (req, res) {38+ res.json(req.range(75))39+ })40+41+ request(app)42+ .get('/')43+ .set('Range', 'bytes=0-')44+ .expect(200, '[{"start":0,"end":74}]', done)45 })46 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);47+ it('should have a .type', function (done) {48+ var app = express()49+50+ app.use(function (req, res) {51+ res.json(req.range(120).type)52+ })53+54+ request(app)55+ .get('/')56+ .set('Range', 'bytes=0-100')57+ .expect(200, '"bytes"', done)58 })59+60+ it('should accept any type', function (done) {61+ var app = express()62+63+ app.use(function (req, res) {64+ res.json(req.range(120).type)65+ })66+67+ request(app)68+ .get('/')69+ .set('Range', 'users=0-2')70+ .expect(200, '"users"', done)71+ })72+73+ it('should return undefined if no range', function (done) {74+ var app = express()75+76+ app.use(function (req, res) {77+ res.send(String(req.range(120)))78+ })79+80+ request(app)81+ .get('/')82+ .expect(200, 'undefined', done)83+ })84 })85 86 describe('.range(size, options)', function(){87 describe('with "combine: true" option', function(){41- it('should return combined ranges', function(){42- var ranges = [{ start: 0, end: 100 }]43- ranges.type = 'bytes'44- assert.deepEqual(req('bytes=0-50,51-100').range(120, { combine: true }), ranges)88+ it('should return combined ranges', function (done) {89+ var app = express()90+91+ app.use(function (req, res) {92+ res.json(req.range(120, {93+ combine: true94+ }))95+ })96+97+ request(app)98+ .get('/')99+ .set('Range', 'bytes=0-50,51-100')100+ .expect(200, '[{"start":0,"end":100}]', done)101 })102 })103 })104 })modified:test/req.stale.js+1 added-1 removed
34 unmodified lines35 36 it('should return true without response headers', function(done){37 var app = express();38 39+ app.disable('x-powered-by')40 app.use(function(req, res){40- res._headers = null;41 res.send(req.stale);42 });43 44 request(app)5 unmodified linesmodified:test/res.redirect.js+4 added-5 removed
1 2-var http = require('http');2 var express = require('..');3 var request = require('supertest');4 var utils = require('./support/utils');5 96 unmodified lines102 .get('/')103 .set('Accept', 'text/html')104 .expect('Content-Type', /html/)105 .expect('Location', 'http://google.com')107- .expect(302, '<p>' + http.STATUS_CODES[302] + '. Redirecting to <a href="http://google.com">http://google.com</a></p>', done);106+ .expect(302, '<p>Found. Redirecting to <a href="http://google.com">http://google.com</a></p>', done)107 })108 109 it('should escape the url', function(done){110 var app = express();7 unmodified lines118 .set('Host', 'http://example.com')119 .set('Accept', 'text/html')120 .expect('Content-Type', /html/)121 .expect('Location', '%3Cla\'me%3E')123- .expect(302, '<p>' + http.STATUS_CODES[302] + '. Redirecting to <a href="%3Cla'me%3E">%3Cla'me%3E</a></p>', done)122+ .expect(302, '<p>Found. Redirecting to <a href="%3Cla'me%3E">%3Cla'me%3E</a></p>', done)123 })124 125 it('should include the redirect type', function(done){126 var app = express();23 unmodified lines150 .get('/')151 .set('Accept', 'text/plain, */*')152 .expect('Content-Type', /plain/)153 .expect('Location', 'http://google.com')155- .expect(302, http.STATUS_CODES[302] + '. Redirecting to http://google.com', done);154+ .expect(302, 'Found. Redirecting to http://google.com', done)155 })156 157 it('should encode the url', function(done){158 var app = express();7 unmodified lines166 .set('Host', 'http://example.com')167 .set('Accept', 'text/plain, */*')168 .expect('Content-Type', /plain/)169 .expect('Location', 'http://example.com/?param=%3Cscript%3Ealert(%22hax%22);%3C/script%3E')171- .expect(302, http.STATUS_CODES[302] + '. Redirecting to http://example.com/?param=%3Cscript%3Ealert(%22hax%22);%3C/script%3E', done)170+ .expect(302, 'Found. Redirecting to http://example.com/?param=%3Cscript%3Ealert(%22hax%22);%3C/script%3E', done)171 })172 173 it('should include the redirect type', function(done){174 var app = express();32 unmodified linesmodified:test/res.send.js+8 added-8 removed
116 unmodified lines117 });118 119 request(app)120 .get('/')121- .expect('ETag', 'W/"3e7-VYgCBglFKiDVAcpzPNt4Sg"')121+ .expect('ETag', 'W/"3e7-qPnkJ3CVdVhFJQvUBfF10TmVA7g"')122 .expect(200, done);123 })124 125 it('should not override Content-Type', function(done){59 unmodified lines185 });186 187 request(app)188 .get('/')189- .expect('ETag', 'W/"3e7-VYgCBglFKiDVAcpzPNt4Sg"')189+ .expect('ETag', 'W/"3e7-qPnkJ3CVdVhFJQvUBfF10TmVA7g"')190 .expect(200, done);191 })192 193 it('should not override Content-Type', function(done){145 unmodified lines339 app.enable('etag');340 341 request(app)342 .get('/')343- .expect('ETag', 'W/"c-ZUfd0NJ26qwjlKF4r8qb2g"')343+ .expect('ETag', 'W/"c-IgR/L5SF7CJQff4wxKGF/vfPuZ0"')344 .expect(200, done);345 });346 347 methods.forEach(function (method) {7 unmodified lines355 });356 357 request(app)358 [method]('/')359- .expect('ETag', 'W/"c-ZUfd0NJ26qwjlKF4r8qb2g"')359+ .expect('ETag', 'W/"c-IgR/L5SF7CJQff4wxKGF/vfPuZ0"')360 .expect(200, done);361 })362 });363 7 unmodified lines371 app.enable('etag');372 373 request(app)374 .get('/')375- .expect('ETag', 'W/"0-1B2M2Y8AsgTpgAmY7PhCfg"')375+ .expect('ETag', 'W/"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"')376 .expect(200, done);377 })378 379 it('should send ETag for long response', function (done) {7 unmodified lines387 app.enable('etag');388 389 request(app)390 .get('/')391- .expect('ETag', 'W/"3e7-VYgCBglFKiDVAcpzPNt4Sg"')391+ .expect('ETag', 'W/"3e7-qPnkJ3CVdVhFJQvUBfF10TmVA7g"')392 .expect(200, done);393 });394 395 it('should not override ETag when manually set', function (done) {73 unmodified lines469 });470 471 request(app)472 .get('/')473- .expect('ETag', '"d-Otu60XkfuuPskIiUxJY4cA"')473+ .expect('ETag', '"d-HwnTDHB9U/PRbFMN1z1wps51lqk"')474 .expect(200, done);475 })476 })477 8 unmodified lines486 });487 488 request(app)489 .get('/')490- .expect('ETag', 'W/"d-Otu60XkfuuPskIiUxJY4cA"')490+ .expect('ETag', 'W/"d-HwnTDHB9U/PRbFMN1z1wps51lqk"')491 .expect(200, done)492 })493 })494 41 unmodified linesmodified:test/res.sendFile.js+2 added-2 removed
155 unmodified lines156 157 describe('with "headers" option', function () {158 it('should accept headers option', function (done) {159 var headers = {160- 'x-success': 'sent',161- 'x-other': 'done'160+ 'x-success': 'sent',161+ 'x-other': 'done'162 };163 var app = createApp(path.resolve(__dirname, 'fixtures/name.txt'), { headers: headers });164 165 request(app)161 unmodified linesmodified:test/Router.js+46 added
51 unmodified lines52 53 router.handle({ url: '', method: 'GET' }, {}, done);54 });55 56+ it('should handle missing URL', function (done) {57+ var router = new Router()58+59+ router.use(function (req, res) {60+ throw new Error('should not be called')61+ })62+63+ router.handle({ method: 'GET' }, {}, done)64+ })65+66 it('should not stack overflow with many registered routes', function(done){67 var handler = function(req, res){ res.end(new Error('wrong handler')) };68 var router = new Router();69 276 unmodified lines346 347 assert.equal(count, methods.length);348 done();349 })350+351+ it('should be called for any URL when "*"', function (done) {352+ var cb = after(4, done)353+ var router = new Router()354+355+ function no () {356+ throw new Error('should not be called')357+ }358+359+ router.all('*', function (req, res) {360+ res.end()361+ })362+363+ router.handle({ url: '/', method: 'GET' }, { end: cb }, no)364+ router.handle({ url: '/foo', method: 'GET' }, { end: cb }, no)365+ router.handle({ url: 'foo', method: 'GET' }, { end: cb }, no)366+ router.handle({ url: '*', method: 'GET' }, { end: cb }, no)367+ })368 })369 370 describe('.use', function() {371 it('should require arguments', function(){8 unmodified lines380 assert.throws(router.use.bind(router, '/', null), /argument handler must be a function/)381 assert.throws(router.use.bind(router, '/', new Date()), /argument handler must be a function/)382 })383 384+ it('should be called for any URL', function (done) {385+ var cb = after(4, done)386+ var router = new Router()387+388+ function no () {389+ throw new Error('should not be called')390+ }391+392+ router.use(function (req, res) {393+ res.end()394+ })395+396+ router.handle({ url: '/', method: 'GET' }, { end: cb }, no)397+ router.handle({ url: '/foo', method: 'GET' }, { end: cb }, no)398+ router.handle({ url: 'foo', method: 'GET' }, { end: cb }, no)399+ router.handle({ url: '*', method: 'GET' }, { end: cb }, no)400+ })401+402 it('should accept array of middleware', function(done){403 var count = 0;404 var router = new Router();405 156 unmodified linesmodified:test/utils.js+8 added-8 removed
3 unmodified lines4 5 describe('utils.etag(body, encoding)', function(){6 it('should support strings', function(){7 utils.etag('express!')8- .should.eql('"8-zZdv4imtWD49AHEviejT6A"')8+ .should.eql('"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')9 })10 11 it('should support utf8 strings', function(){12 utils.etag('express❤', 'utf8')13- .should.eql('"a-fsFba4IxwQS6h6Umb+FNxw"')13+ .should.eql('"a-JBiXf7GyzxwcrxY4hVXUwa7tmks"')14 })15 16 it('should support buffer', function(){17 var buf = new Buffer('express!')18 utils.etag(buf)19- .should.eql('"8-zZdv4imtWD49AHEviejT6A"');19+ .should.eql('"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')20 })21 22 it('should support empty string', function(){23 utils.etag('')24- .should.eql('"0-1B2M2Y8AsgTpgAmY7PhCfg"');24+ .should.eql('"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"')25 })26 })27 28 describe('utils.setCharset(type, charset)', function () {20 unmodified lines49 50 describe('utils.wetag(body, encoding)', function(){51 it('should support strings', function(){52 utils.wetag('express!')53- .should.eql('W/"8-zZdv4imtWD49AHEviejT6A"')53+ .should.eql('W/"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')54 })55 56 it('should support utf8 strings', function(){57 utils.wetag('express❤', 'utf8')58- .should.eql('W/"a-fsFba4IxwQS6h6Umb+FNxw"')58+ .should.eql('W/"a-JBiXf7GyzxwcrxY4hVXUwa7tmks"')59 })60 61 it('should support buffer', function(){62 var buf = new Buffer('express!')63 utils.wetag(buf)64- .should.eql('W/"8-zZdv4imtWD49AHEviejT6A"');64+ .should.eql('W/"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"')65 })66 67 it('should support empty string', function(){68 utils.wetag('')69- .should.eql('W/"0-1B2M2Y8AsgTpgAmY7PhCfg"');69+ .should.eql('W/"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"')70 })71 })modified:.travis.yml+10 added-2 removed
3 unmodified lines4 - "0.12"5 - "1.8"6 - "2.5"7 - "3.3"8- - "4.7"8+ - "4.8"9 - "5.12"10- - "6.9"10+ - "6.10"11+ - "7.6"12+matrix:13+ include:14+ - node_js: "8.0"15+ env: "NVM_NODEJS_ORG_MIRROR=https://nodejs.org/download/nightly"16+ allow_failures:17+ # Allow the nightly installs to fail18+ - env: "NVM_NODEJS_ORG_MIRROR=https://nodejs.org/download/nightly"19 sudo: false20 cache:21 directories:22 - node_modules9 unmodified linesmodified:appveyor.yml+3 added-2 removed
3 unmodified lines4 - nodejs_version: "0.12"5 - nodejs_version: "1.8"6 - nodejs_version: "2.5"7 - nodejs_version: "3.3"8- - nodejs_version: "4.7"8+ - nodejs_version: "4.8"9 - nodejs_version: "5.12"10- - nodejs_version: "6.9"10+ - nodejs_version: "6.10"11+ - nodejs_version: "7.6"12 cache:13 - node_modules14 install:15 - ps: Install-Product node $env:nodejs_version10 unmodified linesmodified:Collaborator-Guide.md+22 added-10 removed
4 unmodified lines5 6 ## PRs and Code contributions7 8 * Tests must pass.9-* Follow existing coding style.9+* Follow the [JavaScript Standard Style](http://standardjs.com/).10 * If you fix a bug, add a test.11 12 ## Branches13 14-* Use the `master` branch for bug fixes or minor work that is intended for the current release stream15-* Use the correspondingly named branch, e.g. `5.0`, for anything intended for a future release of Express 14+Use the `master` branch for bug fixes or minor work that is intended for the15+current release stream.16 17+Use the correspondingly named branch, e.g. `5.0`, for anything intended for18+a future release of Express.19+20 ## Steps for contributing21 19-* [Create an issue](https://github.com/expressjs/express/issues/new) for the bug you want to fix or the feature that you want to add.20-* Create your own [fork](https://github.com/expressjs/express) on github, then checkout your fork.21-* Write your code in your local copy. It's good practice to create a branch for each new issue you work on, although not compulsory.22-* To run the test suite, first install the dependencies by running `npm install`, then run `npm test`.23-* If the tests pass, you can commit your changes to your fork and then create a pull request from there. Make sure to reference your issue from the pull request comments by including the issue number e.g. #123.22+1. [Create an issue](https://github.com/expressjs/express/issues/new) for the23+ bug you want to fix or the feature that you want to add.24+2. Create your own [fork](https://github.com/expressjs/express) on github, then25+ checkout your fork.26+3. Write your code in your local copy. It's good practice to create a branch for27+ each new issue you work on, although not compulsory.28+4. To run the test suite, first install the dependencies by running `npm install`,29+ then run `npm test`.30+5. If the tests pass, you can commit your changes to your fork and then create31+ a pull request from there. Make sure to reference your issue from the pull32+ request comments by including the issue number e.g. `#123`.33 34 ## Issues which are questions35 27-We will typically close any vague issues or questions that are specific to some app you are writing. Please double check the docs and other references before being trigger happy with posting a question issue.36+We will typically close any vague issues or questions that are specific to some37+app you are writing. Please double check the docs and other references before38+being trigger happy with posting a question issue.39 40 Things that will help get your question issue looked at:41 42 * Full and runnable JS code.43 * Clear description of the problem or unexpected behavior.44 * Clear description of the expected result.45 * Steps you have taken to debug it yourself.46 36-If you post a question and do not outline the above items or make it easy for us to understand and reproduce your issue, it will be closed.47+If you post a question and do not outline the above items or make it easy for48+us to understand and reproduce your issue, it will be closed.modified:Contributing.md+3 added-10 removed
1-# Node.js Community Contributing Guide 1.01+# Express.js Community Contributing Guide 1.02 3-This document describes a very simple process suitable for most projects4-in the Node.js ecosystem. Projects are encouraged to adopt this whether they5-are hosted in the Node.js Foundation or not.6-3 The goal of this document is to create a contribution process that:4 5 * Encourages new contributions.6 * Encourages contributors to remain involved.7 * Avoids unnecessary processes and bureaucracy whenever possible.12-* Creates a transparent decision making process which makes it clear how8+* Creates a transparent decision making process that makes it clear how9 contributors can be involved in decision making.10 15-This document is based on much prior art in the Node.js community, io.js,16-and the Node.js project.17-11 ## Vocabulary12 13 * A **Contributor** is any individual creating or commenting on an issue or pull request.14 * A **Committer** is a subset of contributors who have been given write access to the repository.1 unmodified line16 expertise to resolve rare disputes.17 18 # Logging Issues19 27-Log an issue for any question or problem you might have. When in doubt, log an issue, 20+Log an issue for any question or problem you might have. When in doubt, log an issue, and21 any additional policies about what to include will be provided in the responses. The only22 exception is security dislosures which should be sent privately.23 24 Committers may direct you to another repository, ask for additional clarifications, and61 unmodified linesmodified:History.md+84 added
1+5.x2+===3+4+This incorporates all changes after 4.14.1 up to 4.15.0.5+6+ * deps: router@~1.3.07+ - Add `next("router")` to exit from router8+ - Fix case where `router.use` skipped requests routes did not9+ - Skip routing when `req.url` is not set10+ - Use `%o` in path debug to tell types apart11+ - deps: debug@2.6.112+ - deps: setprototypeof@1.0.313+ - perf: add fast match path for `*` route14+15 5.0.0-alpha.3 / 2017-01-2816 ==========================17 18 This is the third Express 5.0 alpha release, based off 4.14.1 and includes47 unmodified lines66 - `req.query` is now a getter instead of a plain property67 * add:68 - `app.router` is a reference to the base router69 70+4.15.0 / 2017-03-0171+===================72+73+ * Add debug message when loading view engine74+ * Add `next("router")` to exit from router75+ * Fix case where `router.use` skipped requests routes did not76+ * Remove usage of `res._headers` private field77+ - Improves compatibility with Node.js 8 nightly78+ * Skip routing when `req.url` is not set79+ * Use `%o` in path debug to tell types apart80+ * Use `Object.create` to setup request & response prototypes81+ * Use `setprototypeof` module to replace `__proto__` setting82+ * Use `statuses` instead of `http` module for status messages83+ * deps: debug@2.6.184+ - Allow colors in workers85+ - Deprecated `DEBUG_FD` environment variable set to `3` or higher86+ - Fix error when running under React Native87+ - Use same color for same namespace88+ - deps: ms@0.7.289+ * deps: etag@~1.8.090+ - Use SHA1 instead of MD5 for ETag hashing91+ - Works with FIPS 140-2 OpenSSL configuration92+ * deps: finalhandler@~1.0.093+ - Fix exception when `err` cannot be converted to a string94+ - Fully URL-encode the pathname in the 40495+ - Only include the pathname in the 404 message96+ - Send complete HTML document97+ - Set `Content-Security-Policy: default-src 'self'` header98+ - deps: debug@2.6.199+ * deps: fresh@0.5.0100+ - Fix false detection of `no-cache` request directive101+ - Fix incorrect result when `If-None-Match` has both `*` and ETags102+ - Fix weak `ETag` matching to match spec103+ - perf: delay reading header values until needed104+ - perf: enable strict mode105+ - perf: hoist regular expressions106+ - perf: remove duplicate conditional107+ - perf: remove unnecessary boolean coercions108+ - perf: skip checking modified time if ETag check failed109+ - perf: skip parsing `If-None-Match` when no `ETag` header110+ - perf: use `Date.parse` instead of `new Date`111+ * deps: qs@6.3.1112+ - Fix array parsing from skipping empty values113+ - Fix compacting nested arrays114+ * deps: send@0.15.0115+ - Fix false detection of `no-cache` request directive116+ - Fix incorrect result when `If-None-Match` has both `*` and ETags117+ - Fix weak `ETag` matching to match spec118+ - Remove usage of `res._headers` private field119+ - Support `If-Match` and `If-Unmodified-Since` headers120+ - Use `res.getHeaderNames()` when available121+ - Use `res.headersSent` when available122+ - deps: debug@2.6.1123+ - deps: etag@~1.8.0124+ - deps: fresh@0.5.0125+ - deps: http-errors@~1.6.1126+ * deps: serve-static@1.12.0127+ - Fix false detection of `no-cache` request directive128+ - Fix incorrect result when `If-None-Match` has both `*` and ETags129+ - Fix weak `ETag` matching to match spec130+ - Remove usage of `res._headers` private field131+ - Send complete HTML document in redirect response132+ - Set default CSP header in redirect response133+ - Support `If-Match` and `If-Unmodified-Since` headers134+ - Use `res.getHeaderNames()` when available135+ - Use `res.headersSent` when available136+ - deps: send@0.15.0137+ * perf: add fast match path for `*` route138+ * perf: improve `req.ips` performance139+140 4.14.1 / 2017-01-28141 ===================142 143 * deps: content-disposition@0.5.23158 unmodified linesmodified:package.json+16 added-13 removed
31 unmodified lines32 "content-disposition": "0.5.2",33 "content-type": "~1.0.2",34 "cookie": "0.3.1",35 "cookie-signature": "1.0.6",36- "debug": "~2.2.0",36+ "debug": "2.6.1",37 "depd": "~1.1.0",38 "encodeurl": "~1.0.1",39 "escape-html": "~1.0.3",40- "etag": "~1.7.0",41- "finalhandler": "0.5.1",42- "fresh": "0.3.0",40+ "etag": "~1.8.0",41+ "finalhandler": "~1.0.0",42+ "fresh": "0.5.0",43 "merge-descriptors": "1.0.1",44 "methods": "~1.1.2",45 "on-finished": "~2.3.0",46 "parseurl": "~1.3.1",47 "path-is-absolute": "1.0.1",48 "path-to-regexp": "0.1.7",49 "proxy-addr": "~1.1.3",50- "qs": "6.2.0",50+ "qs": "6.3.1",51 "range-parser": "~1.2.0",52- "router": "~1.1.5",53- "send": "0.14.2",54- "serve-static": "~1.11.2",52+ "router": "~1.3.0",53+ "send": "0.15.0",54+ "serve-static": "1.12.0",55+ "setprototypeof": "1.0.3",56+ "statuses": "~1.3.1",57 "type-is": "~1.6.14",58 "utils-merge": "1.0.0",59 "vary": "~1.1.0"60 },61 "devDependencies": {62 "after": "0.8.2",61- "body-parser": "1.16.0",63+ "body-parser": "1.17.0",64 "cookie-parser": "~1.4.3",63- "ejs": "2.5.5",64- "express-session": "1.15.0",65+ "ejs": "2.5.6",66+ "express-session": "1.15.1",67 "istanbul": "0.4.5",68 "marked": "0.3.6",67- "method-override": "~2.3.6",69+ "method-override": "2.3.7",70 "mocha": "3.2.0",69- "morgan": "~1.7.0",71+ "morgan": "1.8.1",72 "multiparty": "4.1.3",73+ "pbkdf2-password": "1.2.1",74 "should": "11.2.0",75 "supertest": "1.2.0",76 "connect-redis": "~2.4.1",77 "cookie-session": "~1.2.0",20 unmodified linesadded:Readme-Guide.md+125 added
1+# README guidelines2+3+Every module in the expressjs, pillarjs, and jshttp organizations should have4+a README file named `README.md`. The purpose of the README is to:5+6+- Explain the purpose of the module and how to use it.7+- Act as a landing page (both on GitHub and npmjs.com) for the module to help8+ people find it via search. Middleware module READMEs are also incorporated9+ into https://expressjs.com/en/resources/middleware.html.10+- Encourage community contributions and participation.11+12+Use the [README template](https://github.com/expressjs/express/wiki/README-template)13+to quickly create a new README file.14+15+## Top-level items16+17+**Badges** (optional): At the very top (with no subheading), include any18+applicable badges, such as npm version/downloads, build status, test coverage,19+and so on. Badges should resolve properly (not display a broken image).20+21+Possible badges include:22+- npm version: `[![NPM Version][npm-image]][npm-url]`23+- npm downloads: `[![NPM Downloads][downloads-image]][downloads-url]`24+- Build status: `[![Build Status][travis-image]][travis-url]`25+- Test coverage: `[![Test Coverage][coveralls-image]][coveralls-url]`26+- Tips: `[![Gratipay][gratipay-image]][gratipay-url]`27+28+**Summary**: Following badges, provide a one- or two-sentence description of29+what the module does. This should be the same as the npmjs.org blurb (which30+comes from the description property of `package.json`). Since npm doesn't31+handle markdown for the blurb, avoid using markdown in the summary sentence.32+33+**TOC** (Optional): For longer READMEs, provide a table of contents that has34+a relative link to each section. A tool such as35+[doctoc](https://www.npmjs.com/package/doctoc) makes it very easy to generate36+a TOC.37+38+## Overview39+40+Optionally, include a section of one or two paragraphs with more high-level41+information on what the module does, what problems it solves, why one would42+use it and how. Don't just repeat what's in the summary.43+44+## Installation45+46+Required. This section is typically just:47+48+```sh49+$ npm install module-name50+```51+52+But include any other steps or requirements.53+54+NOTE: Use the `sh` code block to make the shell command display properly on55+the website.56+57+## Basic use58+59+- Provide a general description of how to use the module with code sample.60+ Include any important caveats or restrictions.61+- Explain the most common use cases.62+- Optional: a simple "hello world" type example (where applicable). This63+ example is in addition to the more comprehensive [example section](#examples)64+ later.65+66+## API67+68+Provide complete API documentation.69+70+Formatting conventions: Each function is listed in a 3rd-level heading (`###`),71+like this:72+73+```74+### Function_name(arg, options [, optional_arg] ... )75+```76+77+**Options objects**78+79+For arguments that are objects (for example, options object), describe the80+properties in a table, as follows. This matches the formatting used in the81+[Express API docs](https://expressjs.com/en/4x/api.html).82+83+|Property | Description | Type | Default|84+|----------|-----------|------------|-------------|85+|Name of the property in `monospace`. | Brief description | String, Number, Boolean, etc. | If applicable.|86+87+If all the properties are required (i.e. there are no defaults), then you88+can omit the default column.89+90+Instead of very lengthy descriptions, link out to subsequent paragraphs for91+more detailed explanation of specific cases (e.g. "When this property is set92+to 'foobar', xyz happens; see <link to following section >.)93+94+If there are options properties that are themselves options, use additional95+tables. See [`trust proxy` and `etag` properties](https://expressjs.com/en/4x/api.html#app.settings.table).96+97+## Examples98+99+Every README should have at least one example; ideally more. For code samples,100+be sure to use the `js` code block, for proper display in the website, e.g.:101+102+```js103+var csurf = require('csurf')104+...105+```106+107+## Tests108+109+What tests are included.110+111+How to run them.112+113+The convention for running tests is `npm test`. All our projects should follow114+this convention.115+116+## Contributors117+118+Names of module "owners" (lead developers) and other developers who have119+contributed.120+121+## License122+123+Link to the license, with a short description of what it is, e.g. "MIT" or124+whatever. Ideally, avoid putting the license text directly in the README; link125+to it instead.modified:Readme.md+1 added-1 removed
35 unmodified lines36 * Executable for generating applications quickly37 38 ## Docs & Community39 40- * [Website and Documentation](http://expressjs.com/) - [[website repo](https://github.com/strongloop/expressjs.com)]40+ * [Website and Documentation](http://expressjs.com/) - [[website repo](https://github.com/expressjs/expressjs.com)]41 * [#express](https://webchat.freenode.net/?channels=express) on freenode IRC42 * [Github Organization](https://github.com/expressjs) for Official Middleware & Modules43 * Visit the [Wiki](https://github.com/expressjs/express/wiki)44 * [Google Group](https://groups.google.com/group/express-js) for discussion98 unmodified linesadded:Release-Process.md+186 added
1+# Express Release Process2+3+This document contains the technical aspects of the Express release process. The4+intended audience is those who have been authorized by the Express Technical5+Committee (TC) to create, promote and sign official release builds for Express,6+as npm packages hosted on https://npmjs.com/package/express.7+8+## Who can make releases?9+10+Release authorization is given by the Express TC. Once authorized, an individual11+must have the following access permissions:12+13+### 1. Github release access14+15+The individual making the release will need to be a member of the16+expressjs/express team with Write permission level so they are able to tag the17+release commit and push changes to the expressjs/express repository18+(see Steps 4 and 5).19+20+### 2. npmjs.com release access21+22+The individual making the release will need to be made an owner on the23+`express` package on npmjs.com so they are able to publish the release24+(see Step 6).25+26+## How to publish a release27+28+Before publishing, the following preconditions should be met:29+30+- A release proposal issue or tracking pull request (see "Proposal branch"31+ below) will exist documenting:32+ - the proposed changes33+ - the type of release: patch, minor or major34+ - the version number (according to semantic versioning - http://semver.org)35+- The proposed changes should be complete.36+37+There are two main release flows: patch and non-patch.38+39+The patch flow is for making **patch releases**. As per semantic versioning,40+patch releases are for simple changes, eg: typo fixes, patch dependency updates,41+and simple/low-risk bug fixes. Every other type of change is made via the42+non-patch flow.43+44+### Branch terminology45+46+"Master branch"47+48+- There is a branch in git used for the current major version of Express, named49+ `master`.50+- This branch contains the completed commits for the next patch release of the51+ current major version.52+- Releases for the current major version are published from this branch.53+54+"Version branch"55+56+- For any given major version of Express (current, previous or next) there is57+ a branch in git for that release named `<major-version>.x` (eg: `4.x`).58+- This branch points to the commit of the latest tag for the given major version.59+60+"Release branch"61+62+- For any given major version of Express, there is a branch used for publishing63+ releases.64+- For the current major version of Express, the release branch is the65+ "Master branch" named `master`.66+- For all other major versions of Express, the release branch is the67+ "Version branch" named `<major-version>.x`.68+69+"Proposal branch"70+71+- A branch in git representing a proposed new release of Express. This can be a72+ minor or major release, named `<major-version>.0` for a major release,73+ `<major-version>.<minor-version>` for a minor release.74+- A tracking pull request should exist to document the proposed release,75+ targeted at the appropriate release branch. Prior to opening the tracking76+ pull request the content of the release may have be discussed in an issue.77+- This branch contains the commits accepted so far that implement the proposal78+ in the tracking pull request.79+80+### Patch flow81+82+In the patch flow, simple changes are committed to the release branch which83+acts as an ever-present branch for the next patch release of the associated84+major version of Express.85+86+The release branch is usually kept in a state where it is ready to release.87+Releases are made when sufficient time or change has been made to warrant it.88+This is usually proposed and decided using a github issue.89+90+### Non-patch flow91+92+In the non-patch flow, changes are committed to a temporary proposal branch93+created specifically for that release proposal. The branch is based on the94+most recent release of the major version of Express that the release targets.95+96+Releases are made when all the changes on a proposal branch are complete and97+approved. This is done by merging the proposal branch into the release branch98+(using a fast-forward merge), tagging it with the new version number and99+publishing the release package to npmjs.com.100+101+### Flow102+103+Below is a detailed description of the steps to publish a release.104+105+#### Step 1. Check the release is ready to publish106+107+Check any relevant information to ensure the release is ready, eg: any108+milestone, label, issue or tracking pull request for the release. The release109+is ready when all proposed code, tests and documentation updates are complete110+(either merged, closed or re-targeted to another release).111+112+#### Step 2. (Non-patch flow only) Merge the proposal branch into the release branch113+114+In the patch flow: skip this step.115+116+In the non-patch flow:117+```sh118+$ git checkout <release-branch>119+$ git merge --ff-only <proposal-branch>120+```121+122+<release-branch> - see "Release branch" of "Branches" above.123+<proposal-branch> - see "Proposal branch" of "Non-patch flow" above.124+125+**NOTE:** You may need to rebase the proposal branch to allow a fast-forward126+ merge. Using a fast-forward merge keeps the history clean as it does127+ not introduce merge commits.128+129+### Step 3. Update the History.md and package.json to the new version number130+131+The changes so far for the release should already be documented under the132+"unreleased" section at the top of the History.md file, as per the usual133+development practice. Change "unreleased" to the new release version / date.134+Example diff fragment:135+136+```diff137+-unreleased138+-==========139++4.13.3 / 2015-08-02140++===================141+```142+143+The version property in the package.json should already contain the version of144+the previous release. Change it to the new release version.145+146+Commit these changes together under a single commit with the message set to147+the new release version (eg: `4.13.3`):148+149+```sh150+$ git checkout <release-branch>151+<..edit files..>152+$ git add History.md package.json153+$ git commit -m '<version-number>'154+```155+156+### Step 4. Identify and tag the release commit with the new release version157+158+Create a lightweight tag (rather than an annotated tag) named after the new159+release version (eg: `4.13.3`).160+161+```sh162+$ git tag <version-number>163+```164+165+### Step 5. Push the release branch changes and tag to github166+167+The branch and tag should be pushed directly to the main repository168+(https://github.com/expressjs/express).169+170+```sh171+$ git push origin <release-branch>172+$ git push origin <version-number>173+```174+175+### Step 6. Publish to npmjs.com176+177+Ensure your local working copy is completely clean (no extra or changed files).178+You can use `git status` for this purpose.179+180+```sh181+$ npm login <npm-username>182+$ npm publish183+```184+185+**NOTE:** The version number to publish will be picked up automatically from186+ package.json.