Merge tag '4.14.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 8a387d3, 9375a9a · Browse files · 28 files·+517 added−195 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
28 files+517 added−195 removed
- tests:+200 added−119 removed
- other:+317 added−76 removed
Provenance
- Commit
1dbfee6- Tree
9ed9939- Author
Douglas Christopher Wilson <doug@somethingdoug.com>- Committer
Douglas Christopher Wilson <doug@somethingdoug.com>- Parent 1
8a387d3- Parent 2
9375a9a
28 files changed+517 added−195 removed
modified:examples/error/index.js+3 added
29 unmodified lines303132333435363738394011 unmodified lines29 unmodified lines});
app.get('/next', function(req, res, next){ // We can also pass exceptions to next() // The reason for process.nextTick() is to show that // next() can be called inside an async operation, // in real life it can be a DB read or HTTP request. process.nextTick(function(){ next(new Error('oh no!')); });});11 unmodified linesmodified:examples/markdown/index.js+6 added-10 removed
123456778910111213141516161718192021171819202223242122232417 unmodified lines/** * Module dependencies. */
var escapeHtml = require('escape-html');var express = require('../..');var fs = require('fs');var md = require('marked').parse;var marked = require('marked');
var app = module.exports = express();
// register .md as an engine in express view system
app.engine('md', function(path, options, fn){ fs.readFile(path, 'utf8', function(err, str){ if (err) return fn(err); try { var html = md(str); html = html.replace(/\{([^}]+)\}/g, function(_, name){ return options[name] || ''; }); fn(null, html); var html = marked.parse(str).replace(/\{([^}]+)\}/g, function(_, name){ return escapeHtml(options[name] || ''); }); fn(null, html); } catch(err) { fn(err); } });});
app.set('views', __dirname + '/views');17 unmodified linesmodified:examples/view-locals/user.js+3 added
7 unmodified lines8910111213141516171816 unmodified lines7 unmodified lines this.species = species;}
User.all = function(fn){ // process.nextTick makes sure this function API // behaves in an asynchronous manner, like if it // was a real DB query to read all users. process.nextTick(function(){ fn(null, users); });};16 unmodified linesmodified:lib/request.js+31 added-18 removed
54 unmodified lines55 */56 57 req.get =58 req.header = function header(name) {59+ if (!name) {60+ throw new TypeError('name argument is required to req.get');61+ }62+63+ if (typeof name !== 'string') {64+ throw new TypeError('name must be a string to req.get');65+ }66+67 var lc = name.toLowerCase();68 69 switch (lc) {70 case 'referer':97 unmodified lines168 return accept.languages.apply(accept, arguments);169 };170 171 /**164- * Parse Range header field,165- * capping to the given `size`.172+ * Parse Range header field, capping to the given `size`.173 *167- * Unspecified ranges such as "0-" require168- * knowledge of your resource length. In169- * the case of a byte range this is of course170- * the total number of bytes. If the Range171- * header field is not given `null` is returned,172- * `-1` when unsatisfiable, `-2` when syntactically invalid.174+ * Unspecified ranges such as "0-" require knowledge of your resource length. In175+ * the case of a byte range this is of course the total number of bytes. If the176+ * Range header field is not given `undefined` is returned, `-1` when unsatisfiable,177+ * and `-2` when syntactically invalid.178 *174- * NOTE: remember that ranges are inclusive, so175- * for example "Range: users=0-3" should respond176- * with 4 users when available, not 3.179+ * When ranges are returned, the array has a "type" property which is the type of180+ * range that is required (most commonly, "bytes"). Each array element is an object181+ * with a "start" and "end" property for the portion of the range.182 *178- * @param {Number} size179- * @return {Array}183+ * The "combine" option can be set to `true` and overlapping & adjacent ranges184+ * will be combined into a single range.185+ *186+ * NOTE: remember that ranges are inclusive, so for example "Range: users=0-3"187+ * should respond with 4 users when available, not 3.188+ *189+ * @param {number} size190+ * @param {object} [options]191+ * @param {boolean} [options.combine=false]192+ * @return {number|array}193 * @public194 */195 183-req.range = function(size){196+req.range = function range(size, options) {197 var range = this.get('Range');198 if (!range) return;186- return parseRange(size, range);199+ return parseRange(size, range, options);200 };201 202 /**203 * Parse the query string of `req.url`.90 unmodified lines294 295 /**296 * Short-hand for:297 *285- * req.protocol == 'https'298+ * req.protocol === 'https'299 *300 * @return {Boolean}301 * @public302 */136 unmodified lines439 var method = this.method;440 var s = this.res.statusCode;441 442 // GET or HEAD for weak freshness validation only430- if ('GET' != method && 'HEAD' != method) return false;443+ if ('GET' !== method && 'HEAD' !== method) return false;444 445 // 2xx or 304 as per rfc2616 14.26433- if ((s >= 200 && s < 300) || 304 == s) {446+ if ((s >= 200 && s < 300) || 304 === s) {447 return fresh(this.headers, (this.res._headers || {}));448 }449 450 return false;42 unmodified linesmodified:lib/response.js+21 added-9 removed
12 unmodified lines13 */14 15 var contentDisposition = require('content-disposition');16 var deprecate = require('depd')('express');17+var encodeUrl = require('encodeurl');18 var escapeHtml = require('escape-html');19 var http = require('http');20 var onFinished = require('on-finished');21 var path = require('path');149 unmodified lines171 // freshness172 if (req.fresh) this.statusCode = 304;173 174 // strip irrelevant headers174- if (204 == this.statusCode || 304 == this.statusCode) {175+ if (204 === this.statusCode || 304 === this.statusCode) {176 this.removeHeader('Content-Type');177 this.removeHeader('Content-Length');178 this.removeHeader('Transfer-Encoding');179 chunk = '';35 unmodified lines215 // settings216 var app = this.app;217 var replacer = app.get('json replacer');218 var spaces = app.get('json spaces');218- var body = JSON.stringify(val, replacer, spaces);219+ var body = stringify(val, replacer, spaces);220 221 // content-type222 if (!this.get('Content-Type')) {223 this.set('Content-Type', 'application/json');27 unmodified lines251 // settings252 var app = this.app;253 var replacer = app.get('json replacer');254 var spaces = app.get('json spaces');254- var body = JSON.stringify(val, replacer, spaces);255+ var body = stringify(val, replacer, spaces);256 var callback = this.req.query[app.get('jsonp callback name')];257 258 // content-type259 if (!this.get('Content-Type')) {378 unmodified lines638 /**639 * Clear cookie `name`.640 *641 * @param {String} name641- * @param {Object} options642+ * @param {Object} [options]643 * @return {ServerResponse} for chaining644 * @public645 */646 83 unmodified lines730 loc = this.req.get('Referrer') || '/';731 }732 733 // set location733- this.set('Location', loc);734- return this;734+ return this.set('Location', encodeUrl(loc));735 };736 737 /**738 * Redirect to the given `url` with optional response `status`29 unmodified lines768 }769 }770 771 // Set location header772- this.location(address);773- address = this.get('Location');772+ address = this.location(address).get('Location');773 774 // Support text/{plain,html} by default775 this.format({776 text: function(){778- body = statusCodes[status] + '. Redirecting to ' + encodeURI(address);777+ body = statusCodes[status] + '. Redirecting to ' + address;778 },779 780 html: function(){781 var u = escapeHtml(address);165 unmodified lines947 948 // pipe949 file.pipe(res);950 }951+952+/**953+ * Stringify JSON, like JSON.stringify, but v8 optimized.954+ * @private955+ */956+957+function stringify(value, replacer, spaces) {958+ // v8 checks arguments.length for optimizing simple call959+ // https://bugs.chromium.org/p/v8/issues/detail?id=4730960+ return replacer || spaces961+ ? JSON.stringify(value, replacer, spaces)962+ : JSON.stringify(value);963+}modified:lib/utils.js+1 added-2 removed
100 unmodified lines101 var ret = { value: parts[0], quality: 1, params: {}, originalIndex: index };102 103 for (var i = 1; i < parts.length; ++i) {104 var pms = parts[i].split(/ *= */);105- if ('q' == pms[0]) {105+ if ('q' === pms[0]) {106 ret.quality = parseFloat(pms[1]);107 } else {108 ret.params[pms[0]] = pms[1];109 }131 unmodified lines241 */242 243 function parseExtendedQueryString(str) {244 return qs.parse(str, {245- allowDots: false,245 allowPrototypes: true246 });247 }modified:test/acceptance/cookies.js+7 added-12 removed
1 2 var app = require('../../examples/cookies')3 , request = require('supertest');4+var utils = require('../support/utils');5 6 describe('cookies', function(){7 describe('GET /', function(){8 it('should have a form', function(done){4 unmodified lines13 14 it('should respond with no cookies', function(done){15 request(app)16 .get('/')16- .end(function(err, res){17- res.headers.should.not.have.property('set-cookie')18- done()19- })17+ .expect(utils.shouldNotHaveHeader('Set-Cookie'))18+ .expect(200, done)19 })20 21 it('should respond to cookie', function(done){22 request(app)32 unmodified lines55 request(app)56 .post('/')57 .type('urlencoded')58 .send({ remember: 1 })60- .expect(302, function(err, res){61- res.headers.should.have.property('set-cookie')62- done()63- })59+ .expect('Set-Cookie', /remember=1/)60+ .expect(302, done)61 })62 63 it('should no set cookie w/o reminder', function(done){64 request(app)65 .post('/')66 .send({})70- .expect(302, function(err, res){71- res.headers.should.not.have.property('set-cookie')72- done()73- })67+ .expect(utils.shouldNotHaveHeader('Set-Cookie'))68+ .expect(302, done)69 })70 })71 })modified:test/acceptance/downloads.js+2 added-5 removed
13 unmodified lines1415161718192021221819202122237 unmodified lines13 unmodified lines describe('GET /files/amazing.txt', function(){ it('should have a download header', function(done){ request(app) .get('/files/amazing.txt') .end(function(err, res){ res.status.should.equal(200); res.headers.should.have.property('content-disposition', 'attachment; filename="amazing.txt"') done() }) .expect('Content-Disposition', 'attachment; filename="amazing.txt"') .expect(200, done) }) })
describe('GET /files/missing.txt', function(){7 unmodified linesadded:test/support/utils.js+24 added
1+2+/**3+ * Module dependencies.4+ * @private5+ */6+var assert = require('assert');7+8+/**9+ * Module exports.10+ * @public11+ */12+exports.shouldNotHaveHeader = shouldNotHaveHeader;13+14+/**15+ * Assert that a supertest response does not have a header.16+ *17+ * @param {string} header Header name to check18+ * @returns {function}19+ */20+function shouldNotHaveHeader(header) {21+ return function (res) {22+ assert.ok(!(header.toLowerCase() in res.headers), 'should not have header ' + header);23+ };24+}modified:test/middleware.basic.js+2 added-7 removed
30 unmodified lines31 request(app.listen())32 .get('/')33 .set('Content-Type', 'application/json')34 .send('{"foo":"bar"}')35- .end(function(err, res){36- if (err) return done(err);37- res.headers.should.have.property('content-type', 'application/json');38- res.statusCode.should.equal(200);39- res.text.should.equal('{"foo":"bar"}');40- done();41- })35+ .expect('Content-Type', 'application/json')36+ .expect(200, '{"foo":"bar"}', done)37 })38 })39 })modified:test/req.get.js+25 added-1 removed
29 unmodified lines30 .post('/')31 .set('Referrer', 'http://foobar.com')32 .expect('http://foobar.com', done);33 })34+35+ it('should throw missing header name', function (done) {36+ var app = express()37+38+ app.use(function (req, res) {39+ res.end(req.get())40+ })41+42+ request(app)43+ .get('/')44+ .expect(500, /TypeError: name argument is required to req.get/, done)45+ })46+47+ it('should throw for non-string header name', function (done) {48+ var app = express()49+50+ app.use(function (req, res) {51+ res.end(req.get(42))52+ })53+54+ request(app)55+ .get('/')56+ .expect(500, /TypeError: name must be a string to req.get/, done)57+ })58 })35-})59+})modified:test/req.query.js+4 added-4 removed
41 unmodified lines42 it('should not parse complex keys', function (done) {43 var app = createApp('simple');44 45 request(app)46- .get('/?user[name]=tj')46+ .get('/?user%5Bname%5D=tj')47 .expect(200, '{"user[name]":"tj"}', done);48 });49 });50 3 unmodified lines54 return {'length': (str || '').length};55 });56 57 request(app)58- .get('/?user[name]=tj')58+ .get('/?user%5Bname%5D=tj')59 .expect(200, '{"length":17}', done);60 });61 });62 1 unmodified line64 it('should not parse query', function (done) {65 var app = createApp(false);66 67 request(app)68- .get('/?user[name]=tj')68+ .get('/?user%5Bname%5D=tj')69 .expect(200, '{}', done);70 });71 });72 1 unmodified line74 it('should not parse complex keys', function (done) {75 var app = createApp(true);76 77 request(app)78- .get('/?user[name]=tj')78+ .get('/?user%5Bname%5D=tj')79 .expect(200, '{"user[name]":"tj"}', done);80 });81 });82 21 unmodified linesmodified:test/req.range.js+13 added-3 removed
10 unmodified lines11 12 describe('req', function(){13 describe('.range(size)', function(){14 it('should return parsed ranges', function(){15- var ret = [{ start: 0, end: 50 }, { start: 60, end: 100 }];16- ret.type = 'bytes';17- req('bytes=0-50,60-100').range(120).should.eql(ret);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)18 })19 20 it('should cap to the given size', function(){21 var ret = [{ start: 0, end: 74 }];12 unmodified lines34 ret.type = 'bytes';35 assert(req('').range(120) === undefined);36 })37 })38+39+ describe('.range(size, options)', function(){40+ 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)45+ })46+ })47+ })48 })modified:test/res.cookie.js+16 added
148 unmodified lines149 })150 })151 })152 153+ describe('signed without secret', function(){154+ it('should throw an error', function(done){155+ var app = express();156+157+ app.use(cookieParser());158+159+ app.use(function(req, res){160+ res.cookie('name', 'tobi', { signed: true }).end();161+ });162+163+ request(app)164+ .get('/')165+ .expect(500, /secret\S+ required for signed cookies/, done);166+ })167+ })168+169 describe('.signedCookie(name, string)', function(){170 it('should set a signed cookie', function(done){171 var app = express();172 17 unmodified linesmodified:test/res.jsonp.js+3 added-5 removed
1 2 var express = require('../')3 , request = require('supertest')4 , assert = require('assert');5+var utils = require('./support/utils');6 7 describe('res', function(){8 describe('.jsonp(object)', function(){9 it('should respond with jsonp', function(done){126 unmodified lines136 137 request(app)138 .get('/')139 .expect('Content-Type', 'application/vnd.example+json; charset=utf-8')139- .expect(200, '{"hello":"world"}', function (err, res) {140- if (err) return done(err);141- res.headers.should.not.have.property('x-content-type-options');142- done();143- });140+ .expect(utils.shouldNotHaveHeader('X-Content-Type-Options'))141+ .expect(200, '{"hello":"world"}', done);142 })143 144 it('should override previous Content-Types with callback', function(done){145 var app = express();172 unmodified linesmodified:test/res.location.js+27 added-3 removed
11 unmodified lines12 });13 14 request(app)15 .get('/')16- .end(function(err, res){17- res.headers.should.have.property('location', 'http://google.com');18- done();16+ .expect('Location', 'http://google.com')17+ .expect(200, done)18+ })19+20+ it('should encode "url"', function (done) {21+ var app = express()22+23+ app.use(function (req, res) {24+ res.location('https://google.com?q=\u2603 §10').end()25 })26+27+ request(app)28+ .get('/')29+ .expect('Location', 'https://google.com?q=%E2%98%83%20%C2%A710')30+ .expect(200, done)31 })32+33+ it('should not touch already-encoded sequences in "url"', function (done) {34+ var app = express()35+36+ app.use(function (req, res) {37+ res.location('https://google.com?q=%A710').end()38+ })39+40+ request(app)41+ .get('/')42+ .expect('Location', 'https://google.com?q=%A710')43+ .expect(200, done)44+ })45 })46 })modified:test/res.redirect.js+40 added-25 removed
1 2 var http = require('http');3 var express = require('..');4 var request = require('supertest');5+var utils = require('./support/utils');6 7 describe('res', function(){8 describe('.redirect(url)', function(){9 it('should default to a 302 redirect', function(done){7 unmodified lines17 .get('/')18 .expect('location', 'http://google.com')19 .expect(302, done)20 })21+22+ it('should encode "url"', function (done) {23+ var app = express()24+25+ app.use(function (req, res) {26+ res.redirect('https://google.com?q=\u2603 §10')27+ })28+29+ request(app)30+ .get('/')31+ .expect('Location', 'https://google.com?q=%E2%98%83%20%C2%A710')32+ .expect(302, done)33+ })34+35+ it('should not touch already-encoded sequences in "url"', function (done) {36+ var app = express()37+38+ app.use(function (req, res) {39+ res.redirect('https://google.com?q=%A710')40+ })41+42+ request(app)43+ .get('/')44+ .expect('Location', 'https://google.com?q=%A710')45+ .expect(302, done)46+ })47 })48 49 describe('.redirect(status, url)', function(){50 it('should set the response status', function(done){4 unmodified lines55 });56 57 request(app)58 .get('/')32- .end(function(err, res){33- res.statusCode.should.equal(303);34- res.headers.should.have.property('location', 'http://google.com');35- done();36- })59+ .expect('Location', 'http://google.com')60+ .expect(303, done)61 })62 })63 64 describe('.redirect(url, status)', function(){5 unmodified lines70 });71 72 request(app)73 .get('/')50- .end(function(err, res){51- res.statusCode.should.equal(303);52- res.headers.should.have.property('location', 'http://google.com');53- done();54- })74+ .expect('Location', 'http://google.com')75+ .expect(303, done)76 })77 })78 79 describe('when the request method is HEAD', function(){5 unmodified lines85 });86 87 request(app)88 .head('/')68- .end(function(err, res){69- res.headers.should.have.property('location', 'http://google.com');70- res.text.should.equal('');71- done();72- })89+ .expect('Location', 'http://google.com')90+ .expect(302, '', done)91 })92 })93 94 describe('when accepting html', function(){15 unmodified lines110 it('should escape the url', function(done){111 var app = express();112 113 app.use(function(req, res){96- res.redirect('<lame>');114+ res.redirect('<la\'me>');115 });116 117 request(app)118 .get('/')119 .set('Host', 'http://example.com')120 .set('Accept', 'text/html')121 .expect('Content-Type', /html/)104- .expect('Location', '<lame>')105- .expect(302, '<p>' + http.STATUS_CODES[302] + '. Redirecting to <a href="<lame>"><lame></a></p>', done);122+ .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)124 })125 126 it('should include the redirect type', function(done){127 var app = express();38 unmodified lines166 .get('/')167 .set('Host', 'http://example.com')168 .set('Accept', 'text/plain, */*')169 .expect('Content-Type', /plain/)152- .expect('Location', 'http://example.com/?param=<script>alert("hax");</script>')153- .expect(302, http.STATUS_CODES[302] + '. Redirecting to http://example.com/?param=%3Cscript%3Ealert(%22hax%22);%3C/script%3E', done);170+ .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)172 })173 174 it('should include the redirect type', function(done){175 var app = express();23 unmodified lines199 .get('/')200 .set('Accept', 'application/octet-stream')201 .expect('location', 'http://google.com')202 .expect('content-length', '0')185- .expect(302, '', function(err, res){186- if (err) return done(err)187- res.headers.should.not.have.property('content-type');188- done();189- })203+ .expect(utils.shouldNotHaveHeader('Content-Type'))204+ .expect(302, '', done)205 })206 })207 })modified:test/res.send.js+18 added-41 removed
1 unmodified line2 var assert = require('assert');3 var express = require('..');4 var methods = require('methods');5 var request = require('supertest');6+var utils = require('./support/utils');7 8 describe('res', function(){9 describe('.send()', function(){10 it('should set body to ""', function(done){92 unmodified lines103 });104 105 request(app)106 .get('/')106- .end(function(err, res){107- res.headers.should.have.property('content-type', 'text/html; charset=utf-8');108- res.text.should.equal('<p>hey</p>');109- res.statusCode.should.equal(200);110- done();111- })107+ .expect('Content-Type', 'text/html; charset=utf-8')108+ .expect(200, '<p>hey</p>', done);109 })110 111 it('should set ETag', function (done) {112 var app = express();58 unmodified lines171 });172 173 request(app)174 .get('/')178- .end(function(err, res){179- res.headers.should.have.property('content-type', 'application/octet-stream');180- res.text.should.equal('hello');181- res.statusCode.should.equal(200);182- done();183- })175+ .expect('Content-Type', 'application/octet-stream')176+ .expect(200, 'hello', done);177 })178 179 it('should set ETag', function (done) {180 var app = express();17 unmodified lines198 });199 200 request(app)201 .get('/')209- .end(function(err, res){210- res.headers.should.have.property('content-type', 'text/plain; charset=utf-8');211- res.text.should.equal('hey');212- res.statusCode.should.equal(200);213- done();214- })202+ .expect('Content-Type', 'text/plain; charset=utf-8')203+ .expect(200, 'hey', done);204 })205 })206 207 describe('.send(Object)', function(){34 unmodified lines242 });243 244 request(app)245 .get('/')257- .end(function(err, res){258- res.headers.should.not.have.property('content-type');259- res.headers.should.not.have.property('content-length');260- res.headers.should.not.have.property('transfer-encoding');261- res.text.should.equal('');262- done();263- })246+ .expect(utils.shouldNotHaveHeader('Content-Type'))247+ .expect(utils.shouldNotHaveHeader('Content-Length'))248+ .expect(utils.shouldNotHaveHeader('Transfer-Encoding'))249+ .expect(204, '', done);250 })251 })252 253 describe('when .statusCode is 304', function(){5 unmodified lines259 });260 261 request(app)262 .get('/')277- .end(function(err, res){278- res.headers.should.not.have.property('content-type');279- res.headers.should.not.have.property('content-length');280- res.headers.should.not.have.property('transfer-encoding');281- res.text.should.equal('');282- done();283- })263+ .expect(utils.shouldNotHaveHeader('Content-Type'))264+ .expect(utils.shouldNotHaveHeader('Content-Length'))265+ .expect(utils.shouldNotHaveHeader('Transfer-Encoding'))266+ .expect(304, '', done);267 })268 })269 270 it('should always check regardless of length', function(done){147 unmodified lines418 app.enable('etag');419 420 request(app)421 .get('/')439- .expect(shouldNotHaveHeader('ETag'))422+ .expect(utils.shouldNotHaveHeader('ETag'))423 .expect(200, done);424 })425 });426 9 unmodified lines436 app.disable('etag');437 438 request(app)439 .get('/')457- .expect(shouldNotHaveHeader('ETag'))440+ .expect(utils.shouldNotHaveHeader('ETag'))441 .expect(200, done);442 });443 444 it('should send ETag when manually set', function (done) {81 unmodified lines526 });527 528 request(app)529 .get('/')547- .expect(shouldNotHaveHeader('ETag'))530+ .expect(utils.shouldNotHaveHeader('ETag'))531 .expect(200, done);532 })533 })534 })535 })553-554-function shouldNotHaveHeader(header) {555- return function (res) {556- assert.ok(!(header.toLowerCase() in res.headers), 'should not have header ' + header)557- }558-}modified:test/res.sendFile.js+11 added-5 removed
5 unmodified lines6 var onFinished = require('on-finished');7 var path = require('path');8 var should = require('should');9 var fixtures = path.join(__dirname, 'fixtures');10+var utils = require('./support/utils');11 12 describe('res', function(){13 describe('.sendFile(path)', function () {14 it('should error missing path', function (done) {139 unmodified lines154 var app = createApp(path.resolve(__dirname, 'fixtures/does-not-exist'), { headers: headers });155 156 request(app)157 .get('/')157- .expect(404, function (err, res) {158- if (err) return done(err);159- res.headers.should.not.have.property('x-success');160- done();161- });158+ .expect(utils.shouldNotHaveHeader('X-Success'))159+ .expect(404, done);160 });161 });162 163 describe('with "root" option', function () {120 unmodified lines284 .get('/')285 .expect(200, 'got it', done);286 })287 })288+289+ describe('.sendFile(path, options)', function () {290+ it('should pass options to send module', function (done) {291+ request(createApp(path.resolve(fixtures, 'name.txt'), { start: 0, end: 1 }))292+ .get('/')293+ .expect(200, 'to', done)294+ })295+ })296 })297 298 function createApp(path, options, fn) {299 var app = express();7 unmodified linesmodified:test/res.vary.js+3 added-8 removed
1 2 var assert = require('assert');3 var express = require('..');4 var request = require('supertest');5+var utils = require('./support/utils');6 7 describe('res.vary()', function(){8 describe('with no arguments', function(){9 it('should not set Vary', function (done) {5 unmodified lines15 });16 17 request(app)18 .get('/')18- .expect(shouldNotHaveHeader('Vary'))19+ .expect(utils.shouldNotHaveHeader('Vary'))20 .expect(200, done);21 })22 })23 7 unmodified lines31 });32 33 request(app)34 .get('/')34- .expect(shouldNotHaveHeader('Vary'))35+ .expect(utils.shouldNotHaveHeader('Vary'))36 .expect(200, done);37 })38 })39 48 unmodified lines88 .expect(200, done);89 })90 })91 })91-92-function shouldNotHaveHeader(header) {93- return function (res) {94- assert.ok(!(header.toLowerCase() in res.headers), 'should not have header ' + header);95- };96-}modified:test/Route.js+5 added
5 unmodified lines6 , methods = require('methods')7 , assert = require('assert');8 9 describe('Route', function(){10+ it('should work without handlers', function(done) {11+ var req = { method: 'GET', url: '/' }12+ var route = new Route('/foo')13+ route.dispatch(req, {}, done)14+ })15 16 describe('.all', function(){17 it('should add handler', function(done){18 var req = { method: 'GET', url: '/' };225 unmodified linesmodified:.travis.yml+13 added-2 removed
3 unmodified lines4 - "0.12"5 - "1.8"6 - "2.5"7 - "3.3"8- - "4.2"8+ - "4.4"9+ - "5.11"10+ - "6.2"11 sudo: false12+cache:13+ directories:14+ - node_modules15+before_install:16+ # Remove all non-test dependencies10-before_install: "npm rm --save-dev connect-redis"17+ - "npm rm --save-dev connect-redis"18+19+ # Update Node.js modules20+ - "test ! -d node_modules || npm prune"21+ - "test ! -d node_modules || npm rebuild"22 script: "npm run-script test-ci"23 after_script: "npm install coveralls@2.10.0 && cat ./coverage/lcov.info | coveralls"modified:appveyor.yml+7 added-1 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.2"8+ - nodejs_version: "4.4"9+ - nodejs_version: "5.11"10+ - nodejs_version: "6.2"11+cache:12+ - node_modules13 install:14 - ps: Install-Product node $env:nodejs_version15 - npm rm --save-dev connect-redis16+ - if exist node_modules npm prune17+ - if exist node_modules npm rebuild18 - npm install19 build: off20 test_script:21 - node --version3 unmodified linesadded:Collaborator-Guide.md+36 added
1+2+## Website Issues3+4+Open issues for the expressjs.com website in https://github.com/expressjs/expressjs.com.5+6+## PRs and Code contributions7+8+* Tests must pass.9+* Follow existing coding style.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 16+17+## Steps for contributing18+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.24+25+## Issues which are questions26+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.28+29+Things that will help get your question issue looked at:30+31+* Full and runnable JS code.32+* Clear description of the problem or unexpected behavior.33+* Clear description of the expected result.34+* Steps you have taken to debug it yourself.35+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.modified:Contributing.md+84 added-13 removed
1-# Contributing1+# Node.js Community Contributing Guide 1.02 3-## PRs and Code contributions3+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 5-* Tests must pass.6-* Follow existing coding style.7-* If you fix a bug, add a test.7+The goal of this document is to create a contribution process that:8 9+* Encourages new contributions.10+* Encourages contributors to remain involved.11+* Avoids unnecessary processes and bureaucracy whenever possible.12+* Creates a transparent decision making process which makes it clear how13+contributors can be involved in decision making.14 10-## Issues which are questions15+This document is based on much prior art in the Node.js community, io.js,16+and the Node.js project.17 12-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.18+## Vocabulary19 14-Things that will help get your question issue looked at:20+* A **Contributor** is any individual creating or commenting on an issue or pull request.21+* A **Committer** is a subset of contributors who have been given write access to the repository.22+* A **TC (Technical Committee)** is a group of committers representing the required technical 23+expertise to resolve rare disputes.24 16-* Full and runnable JS code.17-* Clear description of the problem or unexpected behavior.18-* Clear description of the expected result.19-* Steps you have taken to debug it yourself.25+# Logging Issues26 21-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.27+Log an issue for any question or problem you might have. When in doubt, log an issue, 28+any additional policies about what to include will be provided in the responses. The only29+exception is security dislosures which should be sent privately.30+31+Committers may direct you to another repository, ask for additional clarifications, and32+add appropriate metadata before the issue is addressed.33+34+Please be courteous, respectful, and every participant is expected to follow the 35+project's Code of Conduct.36+37+# Contributions38+39+Any change to resources in this repository must be through pull requests. This applies to all changes40+to documentation, code, binary files, etc. Even long term committers and TC members must use41+pull requests.42+43+No pull request can be merged without being reviewed.44+45+For non-trivial contributions, pull requests should sit for at least 36 hours to ensure that46+contributors in other timezones have time to review. Consideration should also be given to 47+weekends and other holiday periods to ensure active committers all have reasonable time to 48+become involved in the discussion and review process if they wish.49+50+The default for each contribution is that it is accepted once no committer has an objection.51+During review committers may also request that a specific contributor who is most versed in a 52+particular area gives a "LGTM" before the PR can be merged. There is no additional "sign off" 53+process for contributions to land. Once all issues brought by committers are addressed it can 54+be landed by any committer.55+56+In the case of an objection being raised in a pull request by another committer, all involved 57+committers should seek to arrive at a consensus by way of addressing concerns being expressed 58+by discussion, compromise on the proposed change, or withdrawal of the proposed change.59+60+If a contribution is controversial and committers cannot agree about how to get it to land61+or if it should land then it should be escalated to the TC. TC members should regularly62+discuss pending contributions in order to find a resolution. It is expected that only a 63+small minority of issues be brought to the TC for resolution and that discussion and 64+compromise among committers be the default resolution mechanism.65+66+# Becoming a Committer67+68+All contributors who land a non-trivial contribution should be on-boarded in a timely manner,69+and added as a committer, and be given write access to the repository.70+71+Committers are expected to follow this policy and continue to send pull requests, go through72+proper review, and have other committers merge their pull requests.73+74+# TC Process75+76+The TC uses a "consensus seeking" process for issues that are escalated to the TC. 77+The group tries to find a resolution that has no open objections among TC members.78+If a consensus cannot be reached that has no objections then a majority wins vote79+is called. It is also expected that the majority of decisions made by the TC are via 80+a consensus seeking process and that voting is only used as a last-resort.81+82+Resolution may involve returning the issue to committers with suggestions on how to 83+move forward towards a consensus. It is not expected that a meeting of the TC 84+will resolve all issues on its agenda during that meeting and may prefer to continue85+the discussion happening among the committers.86+87+Members can be added to the TC at any time. Any committer can nominate another committer88+to the TC and the TC uses its standard consensus seeking process to evaluate whether or89+not to add this new member. Members who do not participate consistently at the level of 90+a majority of the other members are expected to resign.91+92+modified:History.md+85 added
1+5.x2+===3+4+This incorporates all changes after 4.13.1 up to 4.14.0.5+6 5.0.0-alpha.2 / 2015-07-067 ==========================8 9 This is the second Express 5.0 alpha release, based off 4.13.1 and includes29 unmodified lines39 - `req.query` is now a getter instead of a plain property40 * add:41 - `app.router` is a reference to the base router42 43+4.14.0 / 2016-06-1644+===================45+46+ * Add `acceptRanges` option to `res.sendFile`/`res.sendfile`47+ * Add `cacheControl` option to `res.sendFile`/`res.sendfile`48+ * Add `options` argument to `req.range`49+ - Includes the `combine` option50+ * Encode URL in `res.location`/`res.redirect` if not already encoded51+ * Fix some redirect handling in `res.sendFile`/`res.sendfile`52+ * Fix Windows absolute path check using forward slashes53+ * Improve error with invalid arguments to `req.get()`54+ * Improve performance for `res.json`/`res.jsonp` in most cases55+ * Improve `Range` header handling in `res.sendFile`/`res.sendfile`56+ * deps: accepts@~1.3.357+ - Fix including type extensions in parameters in `Accept` parsing58+ - Fix parsing `Accept` parameters with quoted equals59+ - Fix parsing `Accept` parameters with quoted semicolons60+ - Many performance improvments61+ - deps: mime-types@~2.1.1162+ - deps: negotiator@0.6.163+ * deps: content-type@~1.0.264+ - perf: enable strict mode65+ * deps: cookie@0.3.166+ - Add `sameSite` option67+ - Fix cookie `Max-Age` to never be a floating point number68+ - Improve error message when `encode` is not a function69+ - Improve error message when `expires` is not a `Date`70+ - Throw better error for invalid argument to parse71+ - Throw on invalid values provided to `serialize`72+ - perf: enable strict mode73+ - perf: hoist regular expression74+ - perf: use for loop in parse75+ - perf: use string concatination for serialization76+ * deps: finalhandler@0.5.077+ - Change invalid or non-numeric status code to 50078+ - Overwrite status message to match set status code79+ - Prefer `err.statusCode` if `err.status` is invalid80+ - Set response headers from `err.headers` object81+ - Use `statuses` instead of `http` module for status messages82+ * deps: proxy-addr@~1.1.283+ - Fix accepting various invalid netmasks84+ - Fix IPv6-mapped IPv4 validation edge cases85+ - IPv4 netmasks must be contingous86+ - IPv6 addresses cannot be used as a netmask87+ - deps: ipaddr.js@1.1.188+ * deps: qs@6.2.089+ - Add `decoder` option in `parse` function90+ * deps: range-parser@~1.2.091+ - Add `combine` option to combine overlapping ranges92+ - Fix incorrectly returning -1 when there is at least one valid range93+ - perf: remove internal function94+ * deps: send@0.14.195+ - Add `acceptRanges` option96+ - Add `cacheControl` option97+ - Attempt to combine multiple ranges into single range98+ - Correctly inherit from `Stream` class99+ - Fix `Content-Range` header in 416 responses when using `start`/`end` options100+ - Fix `Content-Range` header missing from default 416 responses101+ - Fix redirect error when `path` contains raw non-URL characters102+ - Fix redirect when `path` starts with multiple forward slashes103+ - Ignore non-byte `Range` headers104+ - deps: http-errors@~1.5.0105+ - deps: range-parser@~1.2.0106+ - deps: statuses@~1.3.0107+ - perf: remove argument reassignment108+ * deps: serve-static@~1.11.1109+ - Add `acceptRanges` option110+ - Add `cacheControl` option111+ - Attempt to combine multiple ranges into single range112+ - Fix redirect error when `req.url` contains raw non-URL characters113+ - Ignore non-byte `Range` headers114+ - Use status code 301 for redirects115+ - deps: send@0.14.1116+ * deps: type-is@~1.6.13117+ - Fix type error when given invalid type to match against118+ - deps: mime-types@~2.1.11119+ * deps: vary@~1.1.0120+ - Only accept valid field names in the `field` argument121+ * perf: use strict equality when possible122+123 4.13.4 / 2016-01-21124 ===================125 126 * deps: content-disposition@0.5.13058 unmodified linesmodified:package.json+23 added-21 removed
12 unmodified lines13 "Young Jae Sim <hanul@hanul.me>"14 ],15 "license": "MIT",16 "repository": "expressjs/express",17+ "homepage": "http://expressjs.com/",18 "keywords": [19 "express",20 "framework",21 "sinatra",4 unmodified lines26 "app",27 "api"28 ],29 "dependencies": {29- "accepts": "~1.2.12",30+ "accepts": "~1.3.3",31 "array-flatten": "2.0.0",32 "content-disposition": "0.5.1",32- "content-type": "~1.0.1",33- "cookie": "0.1.5",33+ "content-type": "~1.0.2",34+ "cookie": "0.3.1",35 "cookie-signature": "1.0.6",36 "debug": "~2.2.0",37 "depd": "~1.1.0",38+ "encodeurl": "~1.0.1",39 "escape-html": "~1.0.3",40 "etag": "~1.7.0",39- "finalhandler": "0.4.1",41+ "finalhandler": "0.5.0",42 "fresh": "0.3.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.0",48 "path-to-regexp": "0.1.7",47- "proxy-addr": "~1.0.10",48- "qs": "4.0.0",49- "range-parser": "~1.0.3",49+ "proxy-addr": "~1.1.2",50+ "qs": "6.2.0",51+ "range-parser": "~1.2.0",52 "router": "~1.1.3",51- "send": "0.13.1",52- "serve-static": "~1.10.2",53- "type-is": "~1.6.6",53+ "send": "0.14.1",54+ "serve-static": "~1.11.1",55+ "type-is": "~1.6.13",56 "utils-merge": "1.0.0",55- "vary": "~1.0.1"57+ "vary": "~1.1.0"58 },59 "devDependencies": {60 "after": "0.8.1",61+ "body-parser": "~1.15.1",62+ "cookie-parser": "~1.4.3",59- "ejs": "2.3.4",60- "istanbul": "0.4.2",63+ "ejs": "2.4.2",64+ "istanbul": "0.4.3",65 "marked": "0.3.5",62- "mocha": "2.3.4",63- "should": "7.1.1",64- "supertest": "1.1.0",65- "body-parser": "~1.14.2",66+ "method-override": "~2.3.6",67+ "mocha": "2.5.3",68+ "morgan": "~1.7.0",69+ "should": "9.0.2",70+ "supertest": "1.2.0",71 "connect-redis": "~2.4.1",67- "cookie-parser": "~1.4.1",72 "cookie-session": "~1.2.0",73 "express-session": "~1.13.0",74 "jade": "~1.11.0",71- "method-override": "~2.3.5",72- "morgan": "~1.6.1",75 "multiparty": "~4.1.2",74- "vhost": "~3.0.1"76+ "vhost": "~3.0.2"77 },78 "engines": {79 "node": ">= 0.10.0"80 },14 unmodified linesmodified:Readme.md+4 added
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)]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 discussion45 * [Gitter](https://gitter.im/expressjs/express) for support and discussion46 * [Русскоязычная документация](http://jsman.ru/express/)47 48+**PROTIP** Be sure to read [Migrating from 3.x to 4.x](https://github.com/expressjs/express/wiki/Migrating-from-3.x-to-4.x) as well as [New features in 4.x](https://github.com/expressjs/express/wiki/New-features-in-4.x).49+50 ###Security Issues51 52 If you discover a security vulnerability in Express, please see [Security Policies and Procedures](Security.md).53 89 unmodified lines