Skip to content
Myr

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

30 files+867 added−331 removed

modified:examples/auth/index.js+3 added-3 removed
deleted:examples/auth/pass.js-48 removed
modified:examples/error-pages/index.js+11 added-14 removed
58 unmodified lines
5960app.use(function(req, res, next){61 res.status(404);6263 // respond with html page64 if (req.accepts('html')) {65 res.render('404', { url: req.url });66 return;67 }6869 // respond with json70 if (req.accepts('json')) {71 res.send({ error: 'Not found' });72 return;73 }7475 // 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});7576// error-handling middleware, take the same form77// as regular middleware, however they require an
23 unmodified lines
deleted:examples/expose-data-to-client/views/page.jade-14 removed
1html2 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
modified:lib/application.js+9 added-8 removed
23 unmodified lines
24var flatten = require('array-flatten');25var merge = require('utils-merge');26var resolve = require('path').resolve;27var Router = require('router');28var setPrototyeOf = require('setprototypeof')29var slice = Array.prototype.slice;3031/**32 * Application prototype.
76 unmodified lines
109 delete this.settings['trust proxy fn'];110 }111112 // 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 });118119 // setup locals120 this.locals = Object.create(null);
39 unmodified lines
160 req.res = res;161 res.req = req;162163 // alter the prototypes163 req.__proto__ = this.request;164 res.__proto__ = this.response;164 setPrototyeOf(req, this.request)165 setPrototyeOf(res, this.response)166167 // setup locals168 if (!res.locals) {169 res.locals = Object.create(null);
54 unmodified lines
224 // 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 lines
modified:lib/express.js+10 added-2 removed
38 unmodified lines
3940 mixin(app, EventEmitter.prototype, false);41 mixin(app, proto, false);4243 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 })4748 // 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 })5253 app.init();54 return app;55}56
54 unmodified lines
modified:lib/request.js+23 added-8 removed
22 unmodified lines
23var proxyaddr = require('proxy-addr');2425/**26 * Request prototype.27 * @public28 */2929var req = exports = module.exports = {30 __proto__: http.IncomingMessage.prototype31};30var req = Object.create(http.IncomingMessage.prototype)3132/**33 * Module exports.34 * @public35 */3637module.exports = req3839/**40 * Return request header.41 *42 * The `Referrer` header field is special-cased,43 * both `Referrer` and `Referer` are interchangeable.
296 unmodified lines
340341defineGetter(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();344345 // reverse the order (to farthest -> closest)346 // and remove socket address347 addrs.reverse().pop()348349 return addrs350});351352/**353 * Return subdomains as an array.
93 unmodified lines
447 */448449defineGetter(req, 'fresh', function(){450 var method = this.method;440 var s = this.res.statusCode;451 var res = this.res452 var status = res.statusCode453454 // GET or HEAD for weak freshness validation only455 if ('GET' !== method && 'HEAD' !== method) return false;456457 // 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 }464465 return false;466});
36 unmodified lines
503 configurable: true,504 enumerable: true,505 get: getter506 });492};507}
modified:lib/response.js+13 added-7 removed
18 unmodified lines
19var http = require('http');20var onFinished = require('on-finished');21var path = require('path');22var pathIsAbsolute = require('path-is-absolute');23var statuses = require('statuses')24var merge = require('utils-merge');25var sign = require('cookie-signature').sign;26var normalizeType = require('./utils').normalizeType;27var normalizeTypes = require('./utils').normalizeTypes;28var setCharset = require('./utils').setCharset;28var statusCodes = http.STATUS_CODES;29var cookie = require('cookie');30var send = require('send');31var extname = path.extname;32var mime = send.mime;
1 unmodified line
34var vary = require('vary');3536/**37 * Response prototype.38 * @public39 */4040var res = module.exports = {41 __proto__: http.ServerResponse.prototype42};41var res = Object.create(http.ServerResponse.prototype)4243/**44 * Module exports.45 * @public46 */4748module.exports = res4950/**51 * Module variables.52 * @private53 */54
236 unmodified lines
291 * @public292 */293294res.sendStatus = function sendStatus(statusCode) {289 var body = statusCodes[statusCode] || String(statusCode);295 var body = statuses[statusCode] || String(statusCode)296297 this.statusCode = statusCode;298 this.type('txt');299
461 unmodified lines
761762 // 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 },767768 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 },772773 default: function(){774 body = '';
171 unmodified lines
modified:lib/view.js+3 added-1 removed
73 unmodified lines
74 }7576 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 }8283 // store loaded engine84 this.engine = opts.engines[this.ext];
114 unmodified lines
modified:test/app.router.js+57 added-2 removed
75 unmodified lines
76 });7778 request(app)79 .get('/')80 .expect(404, 'Cannot GET /\n', cb);80 .expect(404, cb)8182 request(app)83 .delete('/')84 .expect(200, 'deleted everything', cb);
4 unmodified lines
89 .expect(200, 'deleted everything', cb);90 });91 })9293 describe('decode querystring', function(){93 describe('decode params', function () {94 it('should decode correct params', function(done){95 var app = express();9697 app.get('/:name', function(req, res, next){
464 unmodified lines
562 .expect('users from 1 to 50', done);563 })564565 describe('*', function(){566 it('should capture everything', function (done) {567 var app = express()568569 app.get('*', function (req, res) {570 res.end(req.params[0])571 })572573 request(app)574 .get('/user/tobi.json')575 .expect('/user/tobi.json', done)576 })577578 it('should decore the capture', function (done) {579 var app = express()580581 app.get('*', function (req, res) {582 res.end(req.params[0])583 })584585 request(app)586 .get('/user/tobi%20and%20loki.json')587 .expect('/user/tobi and loki.json', done)588 })589590 it('should denote a greedy capture group', function(done){591 var app = express();592593 app.get('/user/*.json', function(req, res){
337 unmodified lines
931 .expect(200, 'success', done)932 })933 })934935 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()939940 function fn (req, res, next) {941 res.set('X-Hit', '1')942 next('router')943 }944945 router.get('/foo', fn, function (req, res, next) {946 res.end('failure')947 })948949 router.get('/foo', function (req, res, next) {950 res.end('failure')951 })952953 app.use(router)954955 app.get('/foo', function (req, res) {956 res.end('success')957 })958959 request(app)960 .get('/foo')961 .expect('X-Hit', '1')962 .expect(200, 'success', done)963 })964 })965966 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 lines
modified:test/req.fresh.js+1 added-1 removed
34 unmodified lines
3536 it('should return false without response headers', function(done){37 var app = express();3839 app.disable('x-powered-by')40 app.use(function(req, res){40 res._headers = null;41 res.send(req.fresh);42 });4344 request(app)
5 unmodified lines
modified:test/req.ip.js+2 added-2 removed
77 unmodified lines
78 app.use(function(req, res, next){79 res.send(req.ip);80 });8182 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 lines
modified:test/req.is.js+133 added-68 removed
12var express = require('../')3 , request = require('supertest');2var express = require('..')3var request = require('supertest')45function req(ct) {6 var req = {7 headers: {8 'content-type': ct,9 'transfer-encoding': 'chunked'10 },11 __proto__: express.request12 };5describe('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()914 return req;15}10 app.use(function (req, res) {11 res.json(req.is('application/json'))12 })1317describe('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 })2021 it('should return false when not matching', function (done) {22 var app = express()2324 app.use(function (req, res) {25 res.json(req.is('image/jpeg'))26 })2728 request(app)29 .post('/')30 .type('application/json')31 .send('{}')32 .expect(200, 'false', done)33 })3435 it('should ignore charset', function (done) {36 var app = express()3738 app.use(function (req, res) {39 res.json(req.is('application/json'))40 })4142 request(app)43 .post('/')44 .type('application/json; charset=UTF-8')45 .send('{}')46 .expect(200, '"application/json"', done)47 })48 })4950 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()5354 app.use(function (req, res) {55 res.json(req.is('application/json'))56 })5758 request(app)59 .post('/')60 .send('{}')61 .expect(200, 'false', done)62 })63 })6465 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()6838 req('text/html')39 .is('json')40 .should.be.false;69 app.use(function (req, res) {70 res.json(req.is('json'))71 })7273 request(app)74 .post('/')75 .type('application/json')76 .send('{}')77 .expect(200, '"json"', done)78 })79 })8044 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()8450 req('image/jpeg')51 .is('application/json')52 .should.be.false;85 app.use(function (req, res) {86 res.json(req.is('*/json'))87 })8889 request(app)90 .post('/')91 .type('application/json')92 .send('{}')93 .expect(200, '"application/json"', done)94 })54 })9556 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()9862 req('image/jpeg')63 .is('*/json')64 .should.be.false;99 app.use(function (req, res) {100 res.json(req.is('*/html'))101 })102103 request(app)104 .post('/')105 .type('application/json')106 .send('{}')107 .expect(200, 'false', done)108 })10967 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()11273 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 })116117 request(app)118 .post('/')119 .type('application/json; charset=UTF-8')120 .send('{}')121 .expect(200, '"application/json"', done)122 })123 })124125 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()12886 req('text/html')87 .is('image/*')88 .should.be.false;129 app.use(function (req, res) {130 res.json(req.is('application/*'))131 })132133 request(app)134 .post('/')135 .type('application/json')136 .send('{}')137 .expect(200, '"application/json"', done)138 })13991 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()14297 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 })146147 request(app)148 .post('/')149 .type('application/json')150 .send('{}')151 .expect(200, 'false', done)152 })153154 it('should ignore charset', function (done) {155 var app = express()156157 app.use(function (req, res) {158 res.json(req.is('application/*'))159 })160161 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
12var assert = require('assert');3var express = require('..');4var request = require('supertest')55function req(ret) {6 return {7 get: function(){ return ret }8 , __proto__: express.request9 };10}116describe('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()1011 app.use(function (req, res) {12 res.json(req.range(120))13 })1415 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 })2020 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()2324 app.use(function (req, res) {25 res.json(req.range(75))26 })2728 request(app)29 .get('/')30 .set('Range', 'bytes=0-100')31 .expect(200, '[{"start":0,"end":74}]', done)32 })3326 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()3637 app.use(function (req, res) {38 res.json(req.range(75))39 })4041 request(app)42 .get('/')43 .set('Range', 'bytes=0-')44 .expect(200, '[{"start":0,"end":74}]', done)45 })4632 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()4950 app.use(function (req, res) {51 res.json(req.range(120).type)52 })5354 request(app)55 .get('/')56 .set('Range', 'bytes=0-100')57 .expect(200, '"bytes"', done)58 })5960 it('should accept any type', function (done) {61 var app = express()6263 app.use(function (req, res) {64 res.json(req.range(120).type)65 })6667 request(app)68 .get('/')69 .set('Range', 'users=0-2')70 .expect(200, '"users"', done)71 })7273 it('should return undefined if no range', function (done) {74 var app = express()7576 app.use(function (req, res) {77 res.send(String(req.range(120)))78 })7980 request(app)81 .get('/')82 .expect(200, 'undefined', done)83 })84 })8586 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()9091 app.use(function (req, res) {92 res.json(req.range(120, {93 combine: true94 }))95 })9697 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 lines
3536 it('should return true without response headers', function(done){37 var app = express();3839 app.disable('x-powered-by')40 app.use(function(req, res){40 res._headers = null;41 res.send(req.stale);42 });4344 request(app)
5 unmodified lines
modified:test/res.redirect.js+4 added-5 removed
12var http = require('http');2var express = require('..');3var request = require('supertest');4var utils = require('./support/utils');5
96 unmodified lines
102 .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 })108109 it('should escape the url', function(done){110 var app = express();
7 unmodified lines
118 .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&#39;me%3E">%3Cla&#39;me%3E</a></p>', done)122 .expect(302, '<p>Found. Redirecting to <a href="%3Cla&#39;me%3E">%3Cla&#39;me%3E</a></p>', done)123 })124125 it('should include the redirect type', function(done){126 var app = express();
23 unmodified lines
150 .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 })156157 it('should encode the url', function(done){158 var app = express();
7 unmodified lines
166 .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 })172173 it('should include the redirect type', function(done){174 var app = express();
32 unmodified lines
modified:test/res.send.js+8 added-8 removed
116 unmodified lines
117 });118119 request(app)120 .get('/')121 .expect('ETag', 'W/"3e7-VYgCBglFKiDVAcpzPNt4Sg"')121 .expect('ETag', 'W/"3e7-qPnkJ3CVdVhFJQvUBfF10TmVA7g"')122 .expect(200, done);123 })124125 it('should not override Content-Type', function(done){
59 unmodified lines
185 });186187 request(app)188 .get('/')189 .expect('ETag', 'W/"3e7-VYgCBglFKiDVAcpzPNt4Sg"')189 .expect('ETag', 'W/"3e7-qPnkJ3CVdVhFJQvUBfF10TmVA7g"')190 .expect(200, done);191 })192193 it('should not override Content-Type', function(done){
145 unmodified lines
339 app.enable('etag');340341 request(app)342 .get('/')343 .expect('ETag', 'W/"c-ZUfd0NJ26qwjlKF4r8qb2g"')343 .expect('ETag', 'W/"c-IgR/L5SF7CJQff4wxKGF/vfPuZ0"')344 .expect(200, done);345 });346347 methods.forEach(function (method) {
7 unmodified lines
355 });356357 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 lines
371 app.enable('etag');372373 request(app)374 .get('/')375 .expect('ETag', 'W/"0-1B2M2Y8AsgTpgAmY7PhCfg"')375 .expect('ETag', 'W/"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"')376 .expect(200, done);377 })378379 it('should send ETag for long response', function (done) {
7 unmodified lines
387 app.enable('etag');388389 request(app)390 .get('/')391 .expect('ETag', 'W/"3e7-VYgCBglFKiDVAcpzPNt4Sg"')391 .expect('ETag', 'W/"3e7-qPnkJ3CVdVhFJQvUBfF10TmVA7g"')392 .expect(200, done);393 });394395 it('should not override ETag when manually set', function (done) {
73 unmodified lines
469 });470471 request(app)472 .get('/')473 .expect('ETag', '"d-Otu60XkfuuPskIiUxJY4cA"')473 .expect('ETag', '"d-HwnTDHB9U/PRbFMN1z1wps51lqk"')474 .expect(200, done);475 })476 })477
8 unmodified lines
486 });487488 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 lines
modified:test/res.sendFile.js+2 added-2 removed
155 unmodified lines
156157 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 });164165 request(app)
161 unmodified lines
modified:test/Router.js+46 added
51 unmodified lines
5253 router.handle({ url: '', method: 'GET' }, {}, done);54 });5556 it('should handle missing URL', function (done) {57 var router = new Router()5859 router.use(function (req, res) {60 throw new Error('should not be called')61 })6263 router.handle({ method: 'GET' }, {}, done)64 })6566 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 lines
346347 assert.equal(count, methods.length);348 done();349 })350351 it('should be called for any URL when "*"', function (done) {352 var cb = after(4, done)353 var router = new Router()354355 function no () {356 throw new Error('should not be called')357 }358359 router.all('*', function (req, res) {360 res.end()361 })362363 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 })369370 describe('.use', function() {371 it('should require arguments', function(){
8 unmodified lines
380 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 })383384 it('should be called for any URL', function (done) {385 var cb = after(4, done)386 var router = new Router()387388 function no () {389 throw new Error('should not be called')390 }391392 router.use(function (req, res) {393 res.end()394 })395396 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 })401402 it('should accept array of middleware', function(done){403 var count = 0;404 var router = new Router();405
156 unmodified lines
modified:test/utils.js+8 added-8 removed
3 unmodified lines
45describe('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 })1011 it('should support utf8 strings', function(){12 utils.etag('express❤', 'utf8')13 .should.eql('"a-fsFba4IxwQS6h6Umb+FNxw"')13 .should.eql('"a-JBiXf7GyzxwcrxY4hVXUwa7tmks"')14 })1516 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 })2122 it('should support empty string', function(){23 utils.etag('')24 .should.eql('"0-1B2M2Y8AsgTpgAmY7PhCfg"');24 .should.eql('"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"')25 })26})2728describe('utils.setCharset(type, charset)', function () {
20 unmodified lines
4950describe('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 })5556 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 })6061 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 })6667 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 lines
4 - "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"12matrix: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"19sudo: false20cache:21 directories:22 - node_modules
9 unmodified lines
modified:appveyor.yml+3 added-2 removed
3 unmodified lines
4 - 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"12cache:13 - node_modules14install:15 - ps: Install-Product node $env:nodejs_version
10 unmodified lines
modified:Collaborator-Guide.md+22 added-10 removed
4 unmodified lines
56## PRs and Code contributions78* 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.1112## Branches1314* 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 14Use the `master` branch for bug fixes or minor work that is intended for the15current release stream.1617Use the correspondingly named branch, e.g. `5.0`, for anything intended for18a future release of Express.1920## Steps for contributing2119* [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.221. [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.242. Create your own [fork](https://github.com/expressjs/express) on github, then25 checkout your fork.263. 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.284. To run the test suite, first install the dependencies by running `npm install`,29 then run `npm test`.305. 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`.3334## Issues which are questions3527We 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.36We will typically close any vague issues or questions that are specific to some37app you are writing. Please double check the docs and other references before38being trigger happy with posting a question issue.3940Things that will help get your question issue looked at:4142* 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.4636If 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.47If you post a question and do not outline the above items or make it easy for48us 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.023This document describes a very simple process suitable for most projects4in the Node.js ecosystem. Projects are encouraged to adopt this whether they5are hosted in the Node.js Foundation or not.63The goal of this document is to create a contribution process that:45* 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 how9contributors can be involved in decision making.1015This document is based on much prior art in the Node.js community, io.js,16and the Node.js project.1711## Vocabulary1213* 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 line
16expertise to resolve rare disputes.1718# Logging Issues1927Log an issue for any question or problem you might have. When in doubt, log an issue, 20Log an issue for any question or problem you might have. When in doubt, log an issue, and21any additional policies about what to include will be provided in the responses. The only22exception is security dislosures which should be sent privately.2324Committers may direct you to another repository, ask for additional clarifications, and
61 unmodified lines
modified:History.md+84 added
15.x2===34This incorporates all changes after 4.14.1 up to 4.15.0.56 * 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 `*` route14155.0.0-alpha.3 / 2017-01-2816==========================1718This is the third Express 5.0 alpha release, based off 4.14.1 and includes
47 unmodified lines
66 - `req.query` is now a getter instead of a plain property67 * add:68 - `app.router` is a reference to the base router69704.15.0 / 2017-03-0171===================7273 * 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` performance1391404.14.1 / 2017-01-28141===================142143 * deps: content-disposition@0.5.2
3158 unmodified lines
modified:package.json+16 added-13 removed
31 unmodified lines
32 "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 lines
added:Readme-Guide.md+125 added
1# README guidelines23Every module in the expressjs, pillarjs, and jshttp organizations should have4a README file named `README.md`. The purpose of the README is to:56- 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.1112Use the [README template](https://github.com/expressjs/express/wiki/README-template)13to quickly create a new README file.1415## Top-level items1617**Badges** (optional): At the very top (with no subheading), include any18applicable badges, such as npm version/downloads, build status, test coverage,19and so on. Badges should resolve properly (not display a broken image).2021Possible 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]`2728**Summary**: Following badges, provide a one- or two-sentence description of29what the module does. This should be the same as the npmjs.org blurb (which30comes from the description property of `package.json`). Since npm doesn't31handle markdown for the blurb, avoid using markdown in the summary sentence.3233**TOC** (Optional): For longer READMEs, provide a table of contents that has34a relative link to each section. A tool such as35[doctoc](https://www.npmjs.com/package/doctoc) makes it very easy to generate36a TOC.3738## Overview3940Optionally, include a section of one or two paragraphs with more high-level41information on what the module does, what problems it solves, why one would42use it and how. Don't just repeat what's in the summary.4344## Installation4546Required. This section is typically just:4748```sh49$ npm install module-name50```5152But include any other steps or requirements.5354NOTE: Use the `sh` code block to make the shell command display properly on55the website.5657## Basic use5859- 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.6566## API6768Provide complete API documentation.6970Formatting conventions: Each function is listed in a 3rd-level heading (`###`),71like this:7273```74### Function_name(arg, options [, optional_arg] ... )75```7677**Options objects**7879For arguments that are objects (for example, options object), describe the80properties in a table, as follows. This matches the formatting used in the81[Express API docs](https://expressjs.com/en/4x/api.html).8283|Property | Description | Type | Default|84|----------|-----------|------------|-------------|85|Name of the property in `monospace`. | Brief description | String, Number, Boolean, etc. | If applicable.|8687If all the properties are required (i.e. there are no defaults), then you88can omit the default column.8990Instead of very lengthy descriptions, link out to subsequent paragraphs for91more detailed explanation of specific cases (e.g. "When this property is set92to 'foobar', xyz happens; see &lt;link to following section &gt;.)9394If there are options properties that are themselves options, use additional95tables. See [`trust proxy` and `etag` properties](https://expressjs.com/en/4x/api.html#app.settings.table).9697## Examples9899Every README should have at least one example; ideally more. For code samples,100be sure to use the `js` code block, for proper display in the website, e.g.:101102```js103var csurf = require('csurf')104...105```106107## Tests108109What tests are included.110111How to run them.112113The convention for running tests is `npm test`. All our projects should follow114this convention.115116## Contributors117118Names of module "owners" (lead developers) and other developers who have119contributed.120121## License122123Link to the license, with a short description of what it is, e.g. "MIT" or124whatever. Ideally, avoid putting the license text directly in the README; link125to it instead.
modified:Readme.md+1 added-1 removed
35 unmodified lines
36 * Executable for generating applications quickly3738## Docs & Community3940 * [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 discussion
98 unmodified lines
added:Release-Process.md+186 added
1# Express Release Process23This document contains the technical aspects of the Express release process. The4intended audience is those who have been authorized by the Express Technical5Committee (TC) to create, promote and sign official release builds for Express,6as npm packages hosted on https://npmjs.com/package/express.78## Who can make releases?910Release authorization is given by the Express TC. Once authorized, an individual11must have the following access permissions:1213### 1. Github release access1415The individual making the release will need to be a member of the16expressjs/express team with Write permission level so they are able to tag the17release commit and push changes to the expressjs/express repository18(see Steps 4 and 5).1920### 2. npmjs.com release access2122The 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).2526## How to publish a release2728Before publishing, the following preconditions should be met:2930- 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.3637There are two main release flows: patch and non-patch.3839The patch flow is for making **patch releases**. As per semantic versioning,40patch releases are for simple changes, eg: typo fixes, patch dependency updates,41and simple/low-risk bug fixes. Every other type of change is made via the42non-patch flow.4344### Branch terminology4546"Master branch"4748- 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.5354"Version branch"5556- 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.5960"Release branch"6162- 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`.6869"Proposal branch"7071- 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.7980### Patch flow8182In the patch flow, simple changes are committed to the release branch which83acts as an ever-present branch for the next patch release of the associated84major version of Express.8586The release branch is usually kept in a state where it is ready to release.87Releases are made when sufficient time or change has been made to warrant it.88This is usually proposed and decided using a github issue.8990### Non-patch flow9192In the non-patch flow, changes are committed to a temporary proposal branch93created specifically for that release proposal. The branch is based on the94most recent release of the major version of Express that the release targets.9596Releases are made when all the changes on a proposal branch are complete and97approved. This is done by merging the proposal branch into the release branch98(using a fast-forward merge), tagging it with the new version number and99publishing the release package to npmjs.com.100101### Flow102103Below is a detailed description of the steps to publish a release.104105#### Step 1. Check the release is ready to publish106107Check any relevant information to ensure the release is ready, eg: any108milestone, label, issue or tracking pull request for the release. The release109is ready when all proposed code, tests and documentation updates are complete110(either merged, closed or re-targeted to another release).111112#### Step 2. (Non-patch flow only) Merge the proposal branch into the release branch113114In the patch flow: skip this step.115116In the non-patch flow:117```sh118$ git checkout <release-branch>119$ git merge --ff-only <proposal-branch>120```121122<release-branch> - see "Release branch" of "Branches" above.123<proposal-branch> - see "Proposal branch" of "Non-patch flow" above.124125**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.128129### Step 3. Update the History.md and package.json to the new version number130131The 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 usual133development practice. Change "unreleased" to the new release version / date.134Example diff fragment:135136```diff137-unreleased138-==========139+4.13.3 / 2015-08-02140+===================141```142143The version property in the package.json should already contain the version of144the previous release. Change it to the new release version.145146Commit these changes together under a single commit with the message set to147the new release version (eg: `4.13.3`):148149```sh150$ git checkout <release-branch>151<..edit files..>152$ git add History.md package.json153$ git commit -m '<version-number>'154```155156### Step 4. Identify and tag the release commit with the new release version157158Create a lightweight tag (rather than an annotated tag) named after the new159release version (eg: `4.13.3`).160161```sh162$ git tag <version-number>163```164165### Step 5. Push the release branch changes and tag to github166167The branch and tag should be pushed directly to the main repository168(https://github.com/expressjs/express).169170```sh171$ git push origin <release-branch>172$ git push origin <version-number>173```174175### Step 6. Publish to npmjs.com176177Ensure your local working copy is completely clean (no extra or changed files).178You can use `git status` for this purpose.179180```sh181$ npm login <npm-username>182$ npm publish183```184185**NOTE:** The version number to publish will be picked up automatically from186 package.json.