Skip to content
Myr

Merge tag '3.20.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 ca480d7, 85755e3 · Browse files · 10 files+307 added−145 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

10 files+307 added−145 removed

  • tests:+190 added−119 removed
  • other:+117 added−26 removed

10 files+307 added−145 removed

modified:lib/application.js+38 added-2 removed
1/*!2 * express3 * Copyright(c) 2009-2013 TJ Holowaychuk4 * Copyright(c) 2013 Roman Shtylman5 * Copyright(c) 2014-2015 Douglas Christopher Wilson6 * MIT Licensed7 */89/**10 * Module dependencies.11 * @api private12 */1314var finalhandler = require('finalhandler');15var flatten = require('./utils').flatten;
18 unmodified lines
3435var app = exports = module.exports = {};3637/**38 * Variable for trust proxy inheritance back-compat39 * @api private40 */4142var trustProxyDefaultSymbol = '@@symbol:trust_proxy_default';4344/**45 * Initialize the server.46 *47 * - setup default configuration48 * - setup default middleware
24 unmodified lines
73 this.set('query parser', 'extended');74 this.set('subdomain offset', 2);75 this.set('trust proxy', false);7677 // trust proxy inherit back-compat78 Object.defineProperty(this.settings, trustProxyDefaultSymbol, {79 configurable: true,80 value: true81 });8283 debug('booting in %s mode', env);8463 // inherit protos64 this.on('mount', function(parent){85 this.on('mount', function onmount(parent) {86 // inherit trust proxy87 if (this.settings[trustProxyDefaultSymbol] === true88 && typeof parent.settings['trust proxy fn'] === 'function') {89 delete this.settings['trust proxy'];90 delete this.settings['trust proxy fn'];91 }9293 // inherit protos94 this.request.__proto__ = parent.request;95 this.response.__proto__ = parent.response;96 this.engines.__proto__ = parent.engines;97 this.settings.__proto__ = parent.settings;
257 unmodified lines
355 break;356 case 'trust proxy':357 debug('compile trust proxy %s', val);358 this.set('trust proxy fn', compileTrust(val));359360 // trust proxy inherit back-compat361 Object.defineProperty(this.settings, trustProxyDefaultSymbol, {362 configurable: true,363 value: false364 });365366 break;367 }368369 return this;
238 unmodified lines
modified:lib/response.js+15 added-10 removed
1/*!2 * express3 * Copyright(c) 2009-2013 TJ Holowaychuk4 * Copyright(c) 2014-2015 Douglas Christopher Wilson5 * MIT Licensed6 */78/**9 * Module dependencies.10 * @api private11 */1213var contentDisposition = require('content-disposition');14var deprecate = require('depd')('express');
151 unmodified lines
166 len = chunk.length;167 this.set('Content-Length', len);168 }169162 // method check163 var isHead = req.method === 'HEAD';164165 // ETag support166 if (len !== undefined && (isHead || req.method === 'GET')) {167 var etag = app.get('etag fn');168 if (etag && !this.get('ETag')) {169 etag = etag(chunk, encoding);170 etag && this.set('ETag', etag);170 // populate ETag171 var etag;172 var generateETag = len !== undefined && app.get('etag fn');173 if (typeof generateETag === 'function' && !this.get('ETag')) {174 if ((etag = generateETag(chunk, encoding))) {175 this.set('ETag', etag);176 }177 }178179 // freshness
6 unmodified lines
186 this.removeHeader('Transfer-Encoding');187 chunk = '';188 }189185 if (isHead) {190 if (req.method === 'HEAD') {191 // skip body for HEAD192 this.end();193 } else {194 // respond
835 unmodified lines
modified:lib/utils.js+15 added-5 removed
1/*!2 * express3 * Copyright(c) 2009-2013 TJ Holowaychuk4 * Copyright(c) 2014-2015 Douglas Christopher Wilson5 * MIT Licensed6 */78/**9 * Module dependencies.10 * @api private11 */1213var contentDisposition = require('content-disposition');14var contentType = require('content-type');15var deprecate = require('depd')('express');16var mime = require('send').mime;17var basename = require('path').basename;18var etag = require('etag');19var proxyaddr = require('proxy-addr');20var qs = require('qs');21var querystring = require('querystring');13var typer = require('media-typer');2223/**24 * Return strong ETag for `body`.25 *
239 unmodified lines
265 * @return {String}266 * @api private267 */268261exports.setCharset = function(type, charset){262 if (!type || !charset) return type;269exports.setCharset = function setCharset(type, charset) {270 if (!type || !charset) {271 return type;272 }273274 // parse type265 var parsed = typer.parse(type);275 var parsed = contentType.parse(type);276277 // set charset278 parsed.parameters.charset = charset;279280 // format type271 return typer.format(parsed);281 return contentType.format(parsed);282};283284/**285 * Return new empty object.
8 unmodified lines
modified:test/config.js+74 added-29 removed
modified:test/req.ip.js+17 added
33 unmodified lines
34 .get('/')35 .set('X-Forwarded-For', 'client, p1, p2')36 .expect('p1', done);37 })3839 it('should return the addr after trusted proxy, from sub app', function (done) {40 var app = express();41 var sub = express();4243 app.set('trust proxy', 2);44 app.use(sub);4546 sub.use(function (req, res, next) {47 res.send(req.ip);48 });4950 request(app)51 .get('/')52 .set('X-Forwarded-For', 'client, p1, p2')53 .expect(200, 'p1', done);54 })55 })5657 describe('when "trust proxy" is disabled', function(){58 it('should return the remote address', function(done){
39 unmodified lines
modified:test/res.send.js+99 added-90 removed
12var express = require('../')3 , request = require('supertest')4 , assert = require('assert');2var assert = require('assert');3var express = require('..');4var methods = require('methods');5var request = require('supertest');67describe('res', function(){8 describe('.send(null)', function(){9 it('should set body to ""', function(done){
104 unmodified lines
114 done();115 })116 })117117 it('should set ETag', function(done){118 it('should set ETag', function (done) {119 var app = express();120120 app.use(function(req, res){121 app.use(function (req, res) {122 var str = Array(1000).join('-');123 res.send(str);124 });125126 request(app)127 .get('/')128 .expect('ETag', 'W/"3e7-8084ccd1"')128 .end(done);129 .expect(200, done);130 })131131 it('should not set ETag for non-GET/HEAD', function(done){132 var app = express();133134 app.use(function(req, res){135 var str = Array(1000).join('-');136 res.send(str);137 });138139 request(app)140 .post('/')141 .end(function(err, res){142 if (err) return done(err);143 assert(!res.header.etag, 'has an ETag');144 done();145 });146 })147132 it('should not override Content-Type', function(done){133 var app = express();134135 app.use(function(req, res){
50 unmodified lines
186 done();187 })188 })189206 it('should set ETag', function(done){190 it('should set ETag', function (done) {191 var app = express();192209 app.use(function(req, res){193 app.use(function (req, res) {194 var str = Array(1000).join('-');195 res.send(new Buffer(str));196 });197198 request(app)199 .get('/')200 .expect('ETag', 'W/"3e7-8084ccd1"')217 .end(done);201 .expect(200, done);202 })203204 it('should not override Content-Type', function(done){205 var app = express();
141 unmodified lines
347 .get('/?callback=foo')348 .expect('{"foo":"bar"}', done);349 })350367 describe('"etag" setting', function(){368 describe('when enabled', function(){369 it('should send ETag', function(done){351 describe('"etag" setting', function () {352 describe('when enabled', function () {353 it('should send ETag', function (done) {354 var app = express();355372 app.use(function(req, res){356 app.use(function (req, res) {357 res.send('kajdslfkasdf');358 });359360 app.enable('etag');361362 request(app)363 .get('/')380 .expect('etag', 'W/"c-5aee35d8"', done)381 })364 .expect('ETag', 'W/"c-5aee35d8"')365 .expect(200, done);366 });367383 it('should send ETag for empty string response', function(done){384 var app = express()368 methods.forEach(function (method) {369 if (method === 'connect') return;370371 it('should send ETag in response to ' + method.toUpperCase() + ' request', function (done) {372 var app = express();373374 app[method]('/', function (req, res) {375 res.send('kajdslfkasdf');376 });377378 request(app)379 [method]('/')380 .expect('ETag', 'W/"c-5aee35d8"')381 .expect(200, done);382 })383 });384385 it('should send ETag for empty string response', function (done) {386 var app = express();387386 app.use(function(req, res){387 res.send('')388 app.use(function (req, res) {389 res.send('');390 });391390 app.enable('etag')392 app.enable('etag');393394 request(app)395 .get('/')394 .expect('etag', 'W/"0-0"', done)396 .expect('ETag', 'W/"0-0"')397 .expect(200, done);398 })399397 it('should send ETag for long response', function(done){400 it('should send ETag for long response', function (done) {401 var app = express();402400 app.use(function(req, res){403 app.use(function (req, res) {404 var str = Array(1000).join('-');405 res.send(str);406 });407408 app.enable('etag');409410 request(app)411 .get('/')409 .expect('etag', 'W/"3e7-8084ccd1"', done)412 .expect('ETag', 'W/"3e7-8084ccd1"')413 .expect(200, done);414 });415412 it('should not override ETag when manually set', function(done){416 it('should not override ETag when manually set', function (done) {417 var app = express();418415 app.use(function(req, res){419 app.use(function (req, res) {420 res.set('etag', '"asdf"');421 res.send(200);422 });423424 app.enable('etag');425426 request(app)427 .get('/')424 .expect('etag', '"asdf"', done)428 .expect('ETag', '"asdf"')429 .expect(200, done);430 });431427 it('should not send ETag for res.send()', function(done){428 var app = express()432 it('should not send ETag for res.send()', function (done) {433 var app = express();434430 app.use(function(req, res){431 res.send()435 app.use(function (req, res) {436 res.send();437 });438434 app.enable('etag')439 app.enable('etag');440441 request(app)442 .get('/')438 .end(function(err, res){439 res.headers.should.not.have.property('etag');440 done();441 })443 .expect(shouldNotHaveHeader('ETag'))444 .expect(200, done);445 })446 });447445 describe('when disabled', function(){446 it('should send no ETag', function(done){448 describe('when disabled', function () {449 it('should send no ETag', function (done) {450 var app = express();451449 app.use(function(req, res){452 app.use(function (req, res) {453 var str = Array(1000).join('-');454 res.send(str);455 });456457 app.disable('etag');458459 request(app)460 .get('/')458 .end(function(err, res){459 res.headers.should.not.have.property('etag');460 done();461 });461 .expect(shouldNotHaveHeader('ETag'))462 .expect(200, done);463 });464464 it('should send ETag when manually set', function(done){465 it('should send ETag when manually set', function (done) {466 var app = express();467468 app.disable('etag');469469 app.use(function(req, res){470 app.use(function (req, res) {471 res.set('etag', '"asdf"');472 res.send(200);473 });474475 request(app)476 .get('/')476 .expect('etag', '"asdf"', done)477 .expect('ETag', '"asdf"')478 .expect(200, done);479 });480 });481480 describe('when "strong"', function(){481 it('should send strong ETag', function(done){482 var app = express()482 describe('when "strong"', function () {483 it('should send strong ETag', function (done) {484 var app = express();485486 app.set('etag', 'strong');487486 app.use(function(req, res){488 app.use(function (req, res) {489 res.send('hello, world!');490 });491492 request(app)493 .get('/')492 .expect('etag', '"Otu60XkfuuPskIiUxJY4cA=="', done)494 .expect('ETag', '"Otu60XkfuuPskIiUxJY4cA=="')495 .expect(200, done);496 })497 })498496 describe('when "weak"', function(){497 it('should send weak ETag', function(done){498 var app = express()499 describe('when "weak"', function () {500 it('should send weak ETag', function (done) {501 var app = express();502503 app.set('etag', 'weak');504502 app.use(function(req, res){505 app.use(function (req, res) {506 res.send('hello, world!');507 });508509 request(app)510 .get('/')508 .expect('etag', 'W/"d-58988d13"', done)511 .expect('ETag', 'W/"d-58988d13"')512 .expect(200, done)513 })514 })515512 describe('when a function', function(){513 it('should send custom ETag', function(done){514 var app = express()516 describe('when a function', function () {517 it('should send custom ETag', function (done) {518 var app = express();519516 app.set('etag', function(body, encoding){520 app.set('etag', function (body, encoding) {521 var chunk = !Buffer.isBuffer(body)522 ? new Buffer(body, encoding)523 : body;520 chunk.toString().should.equal('hello, world!')521 return '"custom"'524 chunk.toString().should.equal('hello, world!');525 return '"custom"';526 });527524 app.use(function(req, res){528 app.use(function (req, res) {529 res.send('hello, world!');530 });531532 request(app)533 .get('/')530 .expect('etag', '"custom"', done)534 .expect('ETag', '"custom"')535 .expect(200, done);536 })537533 it('should not send falsy ETag', function(done){534 var app = express()538 it('should not send falsy ETag', function (done) {539 var app = express();540536 app.set('etag', function(body, encoding){537 return undefined541 app.set('etag', function (body, encoding) {542 return undefined;543 });544540 app.use(function(req, res){545 app.use(function (req, res) {546 res.send('hello, world!');547 });548549 request(app)550 .get('/')546 .end(function(err, res){547 res.headers.should.not.have.property('etag')548 done();549 })551 .expect(shouldNotHaveHeader('ETag'))552 .expect(200, done);553 })554 })555 })556})557558function shouldNotHaveHeader(header) {559 return function (res) {560 assert.ok(!(header.toLowerCase() in res.headers), 'should not have header ' + header)561 }562}
modified:.travis.yml+2 added-5 removed
modified:History.md+41 added
1unreleased2==========34 * Fix `"trust proxy"` setting to inherit when app is mounted5 * Generate `ETag`s for all request responses6 - No longer restricted to only responses for `GET` and `HEAD` requests7 * Use `content-type` to parse `Content-Type` headers8 * deps: cookie-signature@1.0.69 * deps: send@0.12.110 - Always read the stat size from the file11 - Fix mutating passed-in `options`12 - deps: mime@1.3.413144.11.2 / 2015-02-0115===================1617 * Fix `res.redirect` double-calling `res.end` for `HEAD` requests
672 unmodified lines
690 - `app.router()` - returns the app Router instance691 - `app.route()` - Proxy to the app's `Router#route()` method to create a new route692 - Router & Route - public API6936943.20.0 / 2015-02-18695===================696697 * Fix `"trust proxy"` setting to inherit when app is mounted698 * Generate `ETag`s for all request responses699 - No longer restricted to only responses for `GET` and `HEAD` requests700 * Use `content-type` to parse `Content-Type` headers701 * deps: connect@2.29.0702 - Use `content-type` to parse `Content-Type` headers703 - deps: body-parser@~1.12.0704 - deps: compression@~1.4.1705 - deps: connect-timeout@~1.6.0706 - deps: cookie-parser@~1.3.4707 - deps: cookie-signature@1.0.6708 - deps: csurf@~1.7.0709 - deps: errorhandler@~1.3.4710 - deps: express-session@~1.10.3711 - deps: http-errors@~1.3.1712 - deps: response-time@~2.3.0713 - deps: serve-index@~1.6.2714 - deps: serve-static@~1.9.1715 - deps: type-is@~1.6.0716 * deps: cookie-signature@1.0.6717 * deps: send@0.12.1718 - Always read the stat size from the file719 - Fix mutating passed-in `options`720 - deps: mime@1.3.47217223.19.2 / 2015-02-01723===================724725 * deps: connect@2.28.3
1960 unmodified lines
modified:LICENSE+2 added
1(The MIT License)23Copyright (c) 2009-2014 TJ Holowaychuk <tj@vision-media.ca>4Copyright (c) 2013-2014 Roman Shtylman <shtylman+expressjs@gmail.com>5Copyright (c) 2014-2015 Douglas Christopher Wilson <doug@somethingdoug.com>67Permission is hereby granted, free of charge, to any person obtaining8a copy of this software and associated documentation files (the9'Software'), to deal in the Software without restriction, including
15 unmodified lines
modified:package.json+4 added-4 removed
27 unmodified lines
28 ],29 "dependencies": {30 "accepts": "~1.2.3",31 "content-disposition": "0.5.0",32 "content-type": "~1.0.1",32 "cookie-signature": "1.0.5",33 "cookie-signature": "1.0.6",34 "debug": "~2.1.1",35 "depd": "~1.0.0",36 "escape-html": "1.0.1",37 "etag": "~1.5.1",38 "finalhandler": "0.3.3",39 "fresh": "0.2.4",39 "media-typer": "0.3.0",40 "methods": "~1.1.1",41 "on-finished": "~2.2.0",42 "parseurl": "~1.3.0",43 "path-to-regexp": "0.1.3",44 "proxy-addr": "~1.0.6",45 "qs": "2.3.3",46 "range-parser": "~1.0.2",47 "send": "0.11.1",47 "send": "0.12.1",48 "serve-static": "~1.8.1",49 "type-is": "~1.5.6",50 "vary": "~1.0.0",51 "cookie": "0.1.2",
5 unmodified lines
57 "ejs": "2.1.4",58 "istanbul": "0.3.5",59 "marked": "0.3.3",60 "mocha": "~2.1.0",61 "should": "~4.6.2",61 "should": "~5.0.0",62 "supertest": "~0.15.0",63 "hjs": "~0.0.6",64 "body-parser": "~1.11.0",65 "connect-redis": "~2.2.0",
25 unmodified lines