Skip to content
Myr

Merge tag '3.9.0'

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

authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parents 311e83e, 0dc5836 · Browse files · 50 files+600 added−198 removed
This commit

State

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

Diff stats

50 files+600 added−198 removed

  • tests:+361 added−123 removed
  • other:+239 added−75 removed

50 files+600 added−198 removed

modified:examples/auth/app.js+1 added
modified:examples/big-view/index.js+5 added-2 removed
modified:examples/content-negotiation/index.js+2 added-1 removed
35 unmodified lines
36}3738app.get('/users', format('./users'));3940/* istanbul ignore next */41if (!module.parent) {42 app.listen(3000);42 console.log('listening on port 3000');43 console.log('Express started on port 3000');44}
modified:examples/cookie-sessions/index.js+2 added-1 removed
modified:examples/cookies/app.js+3 added-3 removed
7 unmodified lines
8var cookieParser = require('cookie-parser');9var bodyParser = require('body-parser');1011// custom log format12if ('test' != process.env.NODE_ENV)13 app.use(logger(':method :url'));12if ('test' != process.env.NODE_ENV) app.use(logger(':method :url'));1314// parses request cookies, populating15// req.cookies and req.signedCookies16// when the secret is passed, used
23 unmodified lines
40 if (req.body.remember) res.cookie('remember', 1, { maxAge: minute });41 res.redirect('back');42});4344/* istanbul ignore next */45if (!module.parent){45if (!module.parent) {46 app.listen(3000);47 console.log('Express started on port 3000');48}
modified:examples/downloads/app.js+1 added
36 unmodified lines
37 next(err);38 }39});4041/* istanbul ignore next */42if (!module.parent) {43 app.listen(3000);44 console.log('Express started on port 3000');45}
modified:examples/ejs/index.js+2 added-1 removed
41 unmodified lines
42 header: "Some users"43 });44});4546/* istanbul ignore next */47if (!module.parent) {48 app.listen(3000);48 console.log('Express app started on port 3000');49 console.log('Express started on port 3000');50}
modified:examples/error/index.js+1 added
38 unmodified lines
39// if it were above it would not receive errors40// from app.get() etc41app.use(error);4243/* istanbul ignore next */44if (!module.parent) {45 app.listen(3000);46 console.log('Express started on port 3000');47}
modified:examples/error-pages/index.js+3 added-4 removed
16 unmodified lines
17app.enable('verbose errors');1819// disable them in production20// use $ NODE_ENV=production node examples/error-pages21if ('production' == app.settings.env) {22 app.disable('verbose errors');23}21if ('production' == app.settings.env) app.disable('verbose errors');2223silent || app.use(logger('dev'));2425// Routes
70 unmodified lines
96 res.render('500', { error: err });97});9899100/* istanbul ignore next */101if (!module.parent) {102 app.listen(3000);104 silent || console.log('Express started on port 3000');103 console.log('Express started on port 3000');104}
modified:examples/expose-data-to-client/index.js+5 added-2 removed
55 unmodified lines
56 res.locals.expose.user = req.user;57 res.render('page');58});5960/* istanbul ignore next */61if (!module.parent) {60app.listen(3000);61console.log('app listening on port 3000');62 app.listen(3000);63 console.log('Express started on port 3000');64}
modified:examples/hello-world/index.js+5 added-2 removed
4 unmodified lines
5app.get('/', function(req, res){6 res.send('Hello World');7});89/* istanbul ignore next */10if (!module.parent) {9app.listen(3000);10console.log('Express started on port 3000');11 app.listen(3000);12 console.log('Express started on port 3000');13}
modified:examples/jade/index.js+5 added-2 removed
42 unmodified lines
43app.use(function(err, req, res, next) {44 res.send(err.stack);45});4647/* istanbul ignore next */48if (!module.parent) {47app.listen(3000);48console.log('Express app started on port 3000');49 app.listen(3000);50 console.log('Express started on port 3000');51}
modified:examples/markdown/index.js+1 added
36 unmodified lines
37app.get('/fail', function(req, res){38 res.render('missing', { title: 'Markdown Example' });39});4041/* istanbul ignore next */42if (!module.parent) {43 app.listen(3000);44 console.log('Express started on port 3000');45}
modified:examples/multipart/index.js+1 added
51 unmodified lines
52 // parse the form53 form.parse(req);54});5556/* istanbul ignore next */57if (!module.parent) {58 app.listen(4000);59 console.log('Express started on port 3000');60}
modified:examples/mvc/index.js+2 added-1 removed
91 unmodified lines
92app.use(function(req, res, next){93 res.status(404).render('404', { url: req.originalUrl });94});9596/* istanbul ignore next */97if (!module.parent) {98 app.listen(3000);98 console.log('\n listening on port 3000\n');99 console.log('Express started on port 3000');100}
modified:examples/online/index.js+5 added-2 removed
47 unmodified lines
48 res.send('<p>Users online: ' + ids.length + '</p>' + list(ids));49 });50});5152/* istanbul ignore next */53if (!module.parent) {52app.listen(3000);53console.log('listening on port 3000');54 app.listen(3000);55 console.log('Express started on port 3000');56}
modified:examples/params/app.js+4 added-3 removed
16 unmodified lines
1718// Convert :to and :from to integers1920app.param(['to', 'from'], function(req, res, next, num, name){21 req.params[name] = num = parseInt(num, 10);22 if( isNaN(num) ){21 req.params[name] = parseInt(num, 10);22 if( isNaN(req.params[name]) ){23 next(new Error('failed to parseInt '+num));24 } else {25 next();26 }
35 unmodified lines
62 var names = users.map(function(user){ return user.name; });63 res.send('users ' + names.slice(from, to).join(', '));64});6566/* istanbul ignore next */67if (!module.parent) {68 app.listen(3000);69 console.log('Express started on port 3000');69}70}
modified:examples/resource/app.js+7 added-4 removed
15 unmodified lines
16 var format = req.params.format;17 obj.range(req, res, a, b, format);18 });19 this.get(path + '/:id', obj.show);20 this.delete(path + '/:id', obj.destroy);20 this.delete(path + '/:id', function(req, res){21 var id = parseInt(req.params.id, 10);22 obj.destroy(req, res, id);23 });24};2526// Fake records27
14 unmodified lines
42 },43 show: function(req, res){44 res.send(users[req.params.id] || { error: 'Cannot find user' });45 },43 destroy: function(req, res){44 var id = req.params.id;46 destroy: function(req, res, id){47 var destroyed = id in users;48 delete users[id];49 res.send(destroyed ? 'destroyed' : 'Cannot find user');50 },
34 unmodified lines
85 , '</ul>'86 ].join('\n'));87});8889/* istanbul ignore next */90if (!module.parent) {91 app.listen(3000);92 console.log('Express started on port 3000');90}93}
modified:examples/route-map/index.js+5 added-1 removed
63 unmodified lines
64 }65 }66});6768/* istanbul ignore next */69if (!module.parent) {68app.listen(3000);70 app.listen(3000);71 console.log('Express started on port 3000');72}
modified:examples/route-middleware/index.js+5 added-2 removed
79 unmodified lines
80app.delete('/user/:id', loadUser, andRestrictTo('admin'), function(req, res){81 res.send('Deleted user ' + req.user.name);82});8384/* istanbul ignore next */85if (!module.parent) {84app.listen(3000);85console.log('Express app started on port 3000');86 app.listen(3000);87 console.log('Express started on port 3000');88}
modified:examples/route-separation/index.js+5 added-2 removed
35 unmodified lines
36// Posts3738app.get('/posts', post.list);3940/* istanbul ignore next */41if (!module.parent) {40app.listen(3000);41console.log('Express app started on port 3000');42 app.listen(3000);43 console.log('Express started on port 3000');44}
modified:examples/search/index.js+5 added-2 removed
55 unmodified lines
56app.get('/client.js', function(req, res){57 res.sendfile(__dirname + '/client.js');58});5960/* istanbul ignore next */61if (!module.parent) {60app.listen(3000);61console.log('app listening on port 3000');62 app.listen(3000);63 console.log('Express started on port 3000');64}
modified:examples/session/index.js+5 added-2 removed
25 unmodified lines
26 }27 res.send(body + '<p>viewed <strong>' + req.session.views + '</strong> times.</p>');28});2930/* istanbul ignore next */31if (!module.parent) {30app.listen(3000);31console.log('Express app started on port 3000');32 app.listen(3000);33 console.log('Express started on port 3000');34}
modified:examples/vhost/index.js+5 added-2 removed
42 unmodified lines
4344app.use(vhost('*.example.com', redirect)); // Serves all subdomains via Redirect app45app.use(vhost('example.com', main)); // Serves top level domain via Main server app4647/* istanbul ignore next */48if (!module.parent) {47app.listen(3000);48console.log('Express app started on port 3000');49 app.listen(3000);50 console.log('Express started on port 3000');51}
modified:examples/view-constructor/index.js+1 added
38 unmodified lines
39 // rendering a view from https://github.com/visionmedia/express/blob/master/Readme.md40 res.render('Readme.md');41});4243/* istanbul ignore next */44if (!module.parent) {45 app.listen(3000);46 console.log('Express started on port 3000');47}
modified:examples/view-locals/index.js+5 added-2 removed
143 unmodified lines
144});145146*/147148/* istanbul ignore next */149if (!module.parent) {148app.listen(3000);149console.log('Application listening on port 3000');150 app.listen(3000);151 console.log('Express started on port 3000');152}
modified:examples/web-service/index.js+2 added-1 removed
101 unmodified lines
102app.use(function(req, res){103 res.send(404, { error: "Lame, can't find that" });104});105106/* istanbul ignore next */107if (!module.parent) {108 app.listen(3000);108 console.log('Express server listening on port 3000');109 console.log('Express started on port 3000');110}
modified:lib/application.js+19 added-9 removed
9 unmodified lines
10var query = require('./middleware/query');11var debug = require('debug')('express:application');12var View = require('./view');13var http = require('http');14var compileETag = require('./utils').compileETag;15var compileTrust = require('./utils').compileTrust;16var deprecate = require('./utils').deprecate;1718/**
27 unmodified lines
4647app.defaultConfiguration = function(){48 // default settings49 this.enable('x-powered-by');49 this.enable('etag');50 this.set('etag', 'weak');51 var env = process.env.NODE_ENV || 'development';52 this.set('env', env);53 this.set('subdomain offset', 2);54 this.set('trust proxy', false);
250 unmodified lines
305 * @api public306 */307308app.set = function(setting, val){308 if (1 == arguments.length) {309 if (arguments.length === 1) {310 // app.get(setting)311 return this.settings[setting];310 } else {311 this.settings[setting] = val;312 }313313 if (setting === 'trust proxy') {314 debug('compile trust proxy %j', val);315 this.set('trust proxy fn', compileTrust(val));316 }314 // set value315 this.settings[setting] = val;316318 return this;317 // trigger matched settings318 switch (setting) {319 case 'etag':320 debug('compile etag %s', val);321 this.set('etag fn', compileETag(val));322 break;323 case 'trust proxy':324 debug('compile trust proxy %s', val);325 this.set('trust proxy fn', compileTrust(val));326 break;327 }328329 return this;330};331332/**333 * Return the app's absolute pathname
218 unmodified lines
modified:lib/response.js+17 added-16 removed
10 unmodified lines
11var normalizeTypes = require('./utils').normalizeTypes;12var setCharset = require('./utils').setCharset;13var contentDisposition = require('./utils').contentDisposition;14var deprecate = require('./utils').deprecate;15var etag = require('./utils').etag;15var statusCodes = http.STATUS_CODES;16var cookie = require('cookie');17var send = require('send');18var basename = path.basename;
104 unmodified lines
123 }124 break;125 }126128 // populate Content-Length129 if (undefined !== body && !this.get('Content-Length')) {130 this.set('Content-Length', len = Buffer.isBuffer(body)131 ? body.length132 : Buffer.byteLength(body));133 }134135 // ETag support136 // TODO: W/ support137 if (app.settings.etag && len && ('GET' == req.method || 'HEAD' == req.method)) {138 if (!this.get('ETag')) {139 this.set('ETag', etag(body));140 }141 }142127 // write strings in utf-8128 if ('string' === typeof body) {129 encoding = 'utf8';130 type = this.get('Content-Type');
3 unmodified lines
134 this.set('Content-Type', setCharset(type, 'utf-8'));135 }136 }137138 // populate Content-Length139 if (undefined !== body && !this.get('Content-Length')) {140 len = Buffer.isBuffer(body)141 ? body.length142 : Buffer.byteLength(body, encoding);143 this.set('Content-Length', len);144 }145146 // ETag support147 var etag = len !== undefined && app.get('etag fn');148 if (etag && ('GET' === req.method || 'HEAD' === req.method)) {149 if (!this.get('ETag')) {150 etag = etag(body, encoding);151 etag && this.set('ETag', etag);152 }153 }154155 // freshness156 if (req.fresh) this.statusCode = 304;157158 // strip irrelevant headers
661 unmodified lines
modified:lib/utils.js+70 added-3 removed
2 unmodified lines
3 */45var mime = require('send').mime;6var crc32 = require('buffer-crc32');7var crypto = require('crypto');8var basename = require('path').basename;9var deprecate = require('util').deprecate;10var proxyaddr = require('proxy-addr');11
26 unmodified lines
38 return deprecate(fn, msg);39};4041/**41 * Return ETag for `body`.42 * Return strong ETag for `body`.43 *44 * @param {String|Buffer} body45 * @param {String} [encoding]46 * @return {String}47 * @api private48 */4948exports.etag = function(body){49 return '"' + crc32.signed(body) + '"';50exports.etag = function etag(body, encoding){51 if (body.length === 0) {52 // fast-path empty body53 return '"1B2M2Y8AsgTpgAmY7PhCfg=="'54 }5556 var hash = crypto57 .createHash('md5')58 .update(body, encoding)59 .digest('base64')60 return '"' + hash + '"'61};6263/**64 * Return weak ETag for `body`.65 *66 * @param {String|Buffer} body67 * @param {String} [encoding]68 * @return {String}69 * @api private70 */7172exports.wetag = function wetag(body, encoding){73 if (body.length === 0) {74 // fast-path empty body75 return 'W/"0-0"'76 }7778 var buf = Buffer.isBuffer(body)79 ? body80 : new Buffer(body, encoding)81 var len = buf.length82 return 'W/"' + len.toString(16) + '-' + crc32.unsigned(buf) + '"'83};8485/**86 * Check if `path` looks absolute.87 *88 * @param {String} path89 * @return {Boolean}
107 unmodified lines
197 return ret;198}199200/**201 * Compile "etag" value to function.202 *203 * @param {Boolean|String|Function} val204 * @return {Function}205 * @api private206 */207208exports.compileETag = function(val) {209 var fn;210211 if (typeof val === 'function') {212 return val;213 }214215 switch (val) {216 case true:217 fn = exports.wetag;218 break;219 case false:220 break;221 case 'strong':222 fn = exports.etag;223 break;224 case 'weak':225 fn = exports.wetag;226 break;227 default:228 throw new TypeError('unknown value for etag function: ' + val);229 }230231 return fn;232}233234/**235 * Compile "proxy trust" value to function.236 *237 * @param {Boolean|String|Number|Array|Function} val238 * @return {Function}
54 unmodified lines
modified:test/acceptance/ejs.js+6 added-9 removed
5 unmodified lines
6 describe('GET /', function(){7 it('should respond with html', function(done){8 request(app)9 .get('/')10 .end(function(err, res){11 res.should.have.status(200);12 res.should.have.header('Content-Type', 'text/html; charset=utf-8');13 res.text.should.include('<li>tobi &lt;tobi@learnboost.com&gt;</li>');14 res.text.should.include('<li>loki &lt;loki@learnboost.com&gt;</li>');15 res.text.should.include('<li>jane &lt;jane@learnboost.com&gt;</li>');16 done();17 });10 .expect('Content-Type', 'text/html; charset=utf-8')11 .expect(/<li>tobi &lt;tobi@learnboost\.com&gt;<\/li>/)12 .expect(/<li>loki &lt;loki@learnboost\.com&gt;<\/li>/)13 .expect(/<li>jane &lt;jane@learnboost\.com&gt;<\/li>/)14 .expect(200, done)15 })16 })20})17})
modified:test/acceptance/markdown.js+2 added-2 removed
12var app = require('../../examples/markdown')3 , request = require('supertest');3var request = require('supertest')45describe('markdown', function(){6 describe('GET /', function(){7 it('should respond with html', function(done){
9 unmodified lines
17 .get('/fail')18 .expect(500,done)19 })20 })21})21})
modified:test/acceptance/mvc.js+10 added-17 removed
45 unmodified lines
46 describe('GET /users', function(){47 it('should display a list of users', function(done){48 request(app)49 .get('/users')50 .end(function(err, res){51 res.text.should.include('<h1>Users</h1>');52 res.text.should.include('>TJ<');53 res.text.should.include('>Guillermo<');54 res.text.should.include('>Nathan<');55 done();56 })50 .expect(/<h1>Users<\/h1>/)51 .expect(/>TJ</)52 .expect(/>Guillermo</)53 .expect(/>Nathan</)54 .expect(200, done)55 })56 })5758 describe('GET /user/:id', function(){59 describe('when present', function(){60 it('should display the user', function(done){61 request(app)62 .get('/user/0')65 .end(function(err, res){66 res.text.should.include('<h1>TJ <a href="/user/0/edit">edit');67 done();68 })63 .expect(200, /<h1>TJ <a href="\/user\/0\/edit">edit/, done)64 })6566 it('should display the users pets', function(done){67 request(app)68 .get('/user/0')74 .end(function(err, res){75 res.text.should.include('/pet/0">Tobi');76 res.text.should.include('/pet/1">Loki');77 res.text.should.include('/pet/2">Jane');78 done();79 })69 .expect(/\/pet\/0">Tobi/)70 .expect(/\/pet\/1">Loki/)71 .expect(/\/pet\/2">Jane/)72 .expect(200, done)73 })74 })7576 describe('when not present', function(){
46 unmodified lines
modified:test/acceptance/params.js+18 added-2 removed
1var app = require('../../examples/params/app')2 , request = require('supertest');2var request = require('supertest')34describe('params', function(){5 describe('GET /', function(){6 it('should respond with instructions', function(done){
10 unmodified lines
17 .expect(/user tj/,done)18 })19 })2021 describe('GET /user/9', function(){22 it('should fail to find user', function(done){23 request(app)24 .get('/user/9')25 .expect(/failed to find user/,done)26 })27 })2829 describe('GET /users/0-2', function(){30 it('should respond with three users', function(done){31 request(app)32 .get('/users/0-2')33 .expect(/users tj, tobi/,done)34 })35 })3637 describe('GET /users/foo-bar', function(){38 it('should fail integer parsing', function(done){39 request(app)40 .get('/users/foo-bar')41 .expect(/failed to parseInt foo/,done)28})42 })43 })44})
modified:test/acceptance/resource.js+19 added-3 removed
1var app = require('../../examples/resource/app')2 , request = require('supertest');2var request = require('supertest')34describe('resource', function(){5 describe('GET /', function(){6 it('should respond with instructions', function(done){
18 unmodified lines
25 .expect(/^{"name":"ciaran"}/,done)26 })27 })2829 describe('GET /users/9', function(){30 it('should respond with error', function(done){31 request(app)32 .get('/users/9')33 .expect('{"error":"Cannot find user"}', done)34 })35 })3637 describe('GET /users/1..3', function(){38 it('should respond with users 1 through 3', function(done){39 request(app)40 .get('/users/1..3')
1 unmodified line
42 })43 })4445 describe('DELETE /users/1', function(){38 it('should respond with users 1 through 3', function(done){46 it('should delete user 1', function(done){47 request(app)48 .del('/users/1')49 .expect(/^destroyed/,done)50 })51 })5253 describe('DELETE /users/9', function(){54 it('should fail', function(done){55 request(app)56 .del('/users/9')57 .expect('Cannot find user', done)58 })59 })6061 describe('GET /users/1..3.json', function(){62 it('should respond with users 2 and 3 as json', function(done){63 request(app)64 .get('/users/1..3.json')65 .expect(/^\[null,{"name":"aaron"},{"name":"guillermo"}\]/,done)66 })67 })52})68})
modified:test/acceptance/web-service.js+2 added-6 removed
96 unmodified lines
97 describe('when requesting an invalid route', function(){98 it('should respond with 404 json', function(done){99 request(app)100 .get('/api/something?api-key=bar')101 .end(function(err, res){102 res.should.have.status(404);103 res.should.be.json;104 res.text.should.equal('{"error":"Lame, can\'t find that"}');105 done();106 });101 .expect('Content-Type', /json/)102 .expect(404, '{"error":"Lame, can\'t find that"}', done)103 })104 })105})
modified:test/app.param.js+18 added
155 unmodified lines
156 .get('/foo/bob')157 .expect('2 2 foo,bob', done);158 })159160 it('should work with encoded values', function(done){161 var app = express();162163 app.param('name', function(req, res, next, name){164 req.params.name = name;165 next();166 });167168 app.get('/user/:name', function(req, res){169 var name = req.params.name;170 res.send('' + name);171 });172173 request(app)174 .get('/user/foo%25bar')175 .expect('foo%bar', done);176 })177178 it('should catch thrown error', function(done){179 var app = express();180181 app.param('id', function(req, res, next, id){
60 unmodified lines
modified:test/app.router.js+24 added
532 unmodified lines
533 })534 })535 })536537 describe('when next("route") is called', function(){538 it('should jump to next route', function(done){539 var app = express()540541 function fn(req, res, next){542 res.set('X-Hit', '1')543 next('route')544 }545546 app.get('/foo', fn, function(req, res, next){547 res.end('failure')548 });549550 app.get('/foo', function(req, res){551 res.end('success')552 })553554 request(app)555 .get('/foo')556 .expect('X-Hit', '1')557 .expect(200, 'success', done)558 })559 })560561 describe('when next(err) is called', function(){562 it('should break out of app.router', function(done){563 var app = express()564 , calls = [];
94 unmodified lines
modified:test/config.js+24 added-1 removed
11 unmodified lines
12 it('should return the app when undefined', function(){13 var app = express();14 app.set('foo', undefined).should.equal(app);15 })1617 describe('"etag"', function(){18 it('should throw on bad value', function(){19 var app = express()20 app.set.bind(app, 'etag', 42).should.throw(/unknown value/)21 })2223 it('should set "etag fn"', function(){24 var app = express()25 var fn = function(){}26 app.set('etag', fn)27 app.get('etag fn').should.equal(fn)28 })29 })3031 describe('"trust proxy"', function(){32 it('should set "trust proxy fn"', function(){33 var app = express()34 var fn = function(){}35 app.set('trust proxy', fn)36 app.get('trust proxy fn').should.equal(fn)37 })38 })39 })4041 describe('.get()', function(){42 it('should return undefined when unset', function(){
70 unmodified lines
113 app.set('foo', 'bar');114 app.disabled('foo').should.be.false;115 })116 })94})117})
modified:test/req.fresh.js+6 added-5 removed
4 unmodified lines
5describe('req', function(){6 describe('.fresh', function(){7 it('should return true when the resource is not modified', function(done){8 var app = express();9 var etag = '"12345"';1011 app.use(function(req, res){11 res.set('ETag', '12345');12 res.set('ETag', etag);13 res.send(req.fresh);14 });1516 request(app)17 .get('/')17 .set('If-None-Match', '12345')18 .set('If-None-Match', etag)19 .expect(304, done);20 })2122 it('should return false when the resource is modified', function(done){23 var app = express();2425 app.use(function(req, res){25 res.set('ETag', '123');26 res.set('ETag', '"123"');27 res.send(req.fresh);28 });2930 request(app)31 .get('/')31 .set('If-None-Match', '12345')32 .expect('false', done);32 .set('If-None-Match', '"12345"')33 .expect(200, 'false', done);34 })35 })36})
modified:test/req.stale.js+6 added-5 removed
4 unmodified lines
5describe('req', function(){6 describe('.stale', function(){7 it('should return false when the resource is not modified', function(done){8 var app = express();9 var etag = '"12345"';1011 app.use(function(req, res){11 res.set('ETag', '12345');12 res.set('ETag', etag);13 res.send(req.stale);14 });1516 request(app)17 .get('/')17 .set('If-None-Match', '12345')18 .set('If-None-Match', etag)19 .expect(304, done);20 })2122 it('should return true when the resource is modified', function(done){23 var app = express();2425 app.use(function(req, res){25 res.set('ETag', '123');26 res.set('ETag', '"123"');27 res.send(req.stale);28 });2930 request(app)31 .get('/')31 .set('If-None-Match', '12345')32 .expect('true', done);32 .set('If-None-Match', '"12345"')33 .expect(200, 'true', done);34 })35 })36})
modified:test/res.cookie.js+2 added-5 removed
89 unmodified lines
9091 request(app)92 .get('/')93 .end(function(err, res){94 res.headers['set-cookie'][0].should.not.include('Thu, 01 Jan 1970 00:00:01 GMT');94 res.headers['set-cookie'][0].should.not.containEql('Thu, 01 Jan 1970 00:00:01 GMT');95 done();96 })97 })98
6 unmodified lines
105 });106107 request(app)108 .get('/')109 .end(function(err, res){110 res.headers['set-cookie'][0].should.include('Max-Age=1');111 done();112 })109 .expect('Set-Cookie', /Max-Age=1/, done)110 })111112 it('should not mutate the options object', function(done){113 var app = express();
60 unmodified lines
modified:test/res.download.js+16 added-19 removed
12 unmodified lines
13 });1415 request(app)16 .get('/')17 .end(function(err, res){18 res.should.have.header('Content-Type', 'text/html; charset=UTF-8');19 res.should.have.header('Content-Disposition', 'attachment; filename="user.html"');20 res.text.should.equal('<p>{{user.name}}</p>');21 done();22 });17 .expect('Content-Type', 'text/html; charset=UTF-8')18 .expect('Content-Disposition', 'attachment; filename="user.html"')19 .expect(200, '<p>{{user.name}}</p>', done)20 })21 })2223 describe('.download(path, filename)', function(){
5 unmodified lines
29 });3031 request(app)32 .get('/')36 .end(function(err, res){37 res.should.have.header('Content-Type', 'text/html; charset=UTF-8');38 res.should.have.header('Content-Disposition', 'attachment; filename="document"');39 done();40 });33 .expect('Content-Type', 'text/html; charset=UTF-8')34 .expect('Content-Disposition', 'attachment; filename="document"')35 .expect(200, done)36 })37 })3839 describe('.download(path, fn)', function(){
6 unmodified lines
46 });4748 request(app)49 .get('/')55 .end(function(err, res){56 res.should.have.header('Content-Type', 'text/html; charset=UTF-8');57 res.should.have.header('Content-Disposition', 'attachment; filename="user.html"');58 });50 .expect('Content-Type', 'text/html; charset=UTF-8')51 .expect('Content-Disposition', 'attachment; filename="user.html"')52 .expect(200, function(err){53 assert.ifError(err)54 })55 })56 })5758 describe('.download(path, filename, fn)', function(){
6 unmodified lines
65 });6667 request(app)68 .get('/')73 .end(function(err, res){74 res.should.have.header('Content-Type', 'text/html; charset=UTF-8');75 res.should.have.header('Content-Disposition', 'attachment; filename="document"');76 });69 .expect('Content-Type', 'text/html; charset=UTF-8')70 .expect('Content-Disposition', 'attachment; filename="document"')71 .expect(200, function(err){72 assert.ifError(err)73 })74 })75 })7677 describe('on failure', function(){
38 unmodified lines
modified:test/res.redirect.js+6 added-10 removed
11 unmodified lines
12 });1314 request(app)15 .get('/')16 .end(function(err, res){17 res.statusCode.should.equal(302);18 res.headers.should.have.property('location', 'http://google.com');19 done();20 })16 .expect('location', 'http://google.com')17 .expect(302, done)18 })19 })2021 describe('.redirect(status, url)', function(){
133 unmodified lines
155156 request(app)157 .get('/')158 .set('Accept', 'application/octet-stream')162 .end(function(err, res){163 res.should.have.status(302);164 res.headers.should.have.property('location', 'http://google.com');159 .expect('location', 'http://google.com')160 .expect('content-length', '0')161 .expect(302, '', function(err, res){162 if (err) return done(err)163 res.headers.should.not.have.property('content-type');166 res.headers.should.have.property('content-length', '0');167 res.text.should.equal('');164 done();165 })166 })167 })
1 unmodified line
modified:test/res.send.js+134 added-20 removed
107 unmodified lines
108 });109110 request(app)111 .get('/')112 .expect('ETag', '"-1498647312"')112 .expect('ETag', 'W/"7ff-2796319984"')113 .end(done);114 })115116 it('should not set ETag for non-GET/HEAD', function(done){
80 unmodified lines
197 });198199 request(app)200 .get('/')201 .expect('ETag', '"-1498647312"')201 .expect('ETag', 'W/"7ff-2796319984"')202 .end(done);203 })204205 it('should not override Content-Type', function(done){
84 unmodified lines
290 })291292 it('should always check regardless of length', function(done){293 var app = express();294 var etag = '"asdf"';295296 app.use(function(req, res, next){296 res.set('ETag', 'asdf');297 res.set('ETag', etag);298 res.send('hey');299 });300301 request(app)302 .get('/')302 .set('If-None-Match', 'asdf')303 .set('If-None-Match', etag)304 .expect(304, done);305 })306307 it('should respond with 304 Not Modified when fresh', function(done){
5 unmodified lines
313 });314315 request(app)316 .get('/')316 .set('If-None-Match', '"-1498647312"')317 .set('If-None-Match', 'W/"7ff-2796319984"')318 .expect(304, done);319 })320321 it('should not perform freshness check unless 2xx or 304', function(done){322 var app = express();323 var etag = '"asdf"';324325 app.use(function(req, res, next){326 res.status(500);325 res.set('ETag', 'asdf');327 res.set('ETag', etag);328 res.send('hey');329 });330331 request(app)332 .get('/')331 .set('If-None-Match', 'asdf')333 .set('If-None-Match', etag)334 .expect('hey')335 .expect(500, done);336 })337
10 unmodified lines
348 })349350 describe('"etag" setting', function(){351 describe('when enabled', function(){350 it('should send ETag even when content-length < 1024', function(done){352 it('should send ETag', function(done){353 var app = express();354355 app.use(function(req, res){356 res.send('kajdslfkasdf');357 });358359 app.enable('etag');360361 request(app)362 .get('/')359 .end(function(err, res){360 res.headers.should.have.property('etag');361 done();363 .expect('etag', 'W/"c-1525560792"', done)364 })365366 it('should send ETag for empty string response', function(done){367 var app = express()368369 app.use(function(req, res){370 res.send('')371 });372373 app.enable('etag')374375 request(app)376 .get('/')377 .expect('etag', 'W/"0-0"', done)378 })379365 it('should send ETag ', function(done){380 it('should send ETag for long response', function(done){381 var app = express();382383 app.use(function(req, res){384 var str = Array(1024 * 2).join('-');385 res.send(str);386 });387388 app.enable('etag');389390 request(app)391 .get('/')375 .end(function(err, res){376 res.headers.should.have.property('etag', '"-1498647312"');377 done();392 .expect('etag', 'W/"7ff-2796319984"', done)393 });394395 it('should not override ETag when manually set', function(done){396 var app = express();397398 app.use(function(req, res){399 res.set('etag', '"asdf"');400 res.send(200);401 });402403 app.enable('etag');404405 request(app)406 .get('/')407 .expect('etag', '"asdf"', done)408 });409410 it('should not send ETag for res.send()', function(done){411 var app = express()412413 app.use(function(req, res){414 res.send()415 });416417 app.enable('etag')418419 request(app)420 .get('/')421 .end(function(err, res){422 res.headers.should.not.have.property('etag');423 done();424 })425 })426 });427428 describe('when disabled', function(){429 it('should send no ETag', function(done){
19 unmodified lines
449450 app.disable('etag');451452 app.use(function(req, res){407 res.set('etag', 1);453 res.set('etag', '"asdf"');454 res.send(200);455 });456457 request(app)458 .get('/')413 .end(function(err, res){414 res.headers.should.have.property('etag');415 done();416 });459 .expect('etag', '"asdf"', done)460 });461 });462463 describe('when "strong"', function(){464 it('should send strong ETag', function(done){465 var app = express()466467 app.set('etag', 'strong');468469 app.use(function(req, res){470 res.send('hello, world!');471 });472473 request(app)474 .get('/')475 .expect('etag', '"Otu60XkfuuPskIiUxJY4cA=="', done)476 })477 })478479 describe('when "weak"', function(){480 it('should send weak ETag', function(done){481 var app = express()482483 app.set('etag', 'weak');484485 app.use(function(req, res){486 res.send('hello, world!');487 });488489 request(app)490 .get('/')491 .expect('etag', 'W/"d-1486392595"', done)492 })493 })494495 describe('when a function', function(){496 it('should send custom ETag', function(done){497 var app = express()498499 app.set('etag', function(body, encoding){500 body.should.equal('hello, world!')501 encoding.should.equal('utf8')502 return '"custom"'503 });504505 app.use(function(req, res){506 res.send('hello, world!');507 });508509 request(app)510 .get('/')511 .expect('etag', '"custom"', done)512 })513514 it('should not send falsy ETag', function(done){515 var app = express()516517 app.set('etag', function(body, encoding){518 return undefined519 });520521 app.use(function(req, res){522 res.send('hello, world!');523 });524525 request(app)526 .get('/')527 .end(function(err, res){528 res.headers.should.not.have.property('etag')529 done();530 })531 })532 })533 })534})
modified:test/res.sendfile.js+1 added-5 removed
7 unmodified lines
8 it('should invoke the callback when complete', function(done){9 var app = express();1011 app.use(function(req, res){12 res.sendfile('test/fixtures/user.html', function(err){13 assert(!err);14 req.socket.listeners('error').should.have.length(1); // node's original handler15 done();16 });12 res.sendfile('test/fixtures/user.html', done)13 });1415 request(app)16 .get('/')
246 unmodified lines
modified:test/res.set.js+7 added-6 removed
18 unmodified lines
19 })2021 it('should coerce to a string', function(){22 res.headers = {};23 res.set('ETag', 123);24 res.get('ETag').should.equal('123');23 res.set('X-Number', 123);24 res.get('X-Number').should.equal('123');25 })26 })2728 describe('.set(field, values)', function(){
11 unmodified lines
40 })4142 it('should coerce to an array of strings', function(){43 res.headers = {};44 res.set('ETag', [123, 456]);45 JSON.stringify(res.get('ETag')).should.equal('["123","456"]');44 res.set('X-Numbers', [123, 456]);45 JSON.stringify(res.get('X-Numbers'))46 .should.equal('["123","456"]');47 })4849 it('should not set a charset of one is already set', function () {50 res.headers = {};
21 unmodified lines
72 })7374 it('should coerce to a string', function(){75 res.headers = {};75 res.set({ ETag: 123 });76 res.get('ETag').should.equal('123');76 res.set({ 'X-Number': 123 });77 res.get('X-Number').should.equal('123');78 })79 })80})
modified:test/utils.js+60 added-8 removed
12var utils = require('../lib/utils')3 , assert = require('assert');45describe('utils.etag(body)', function(){5describe('utils.deprecate(fn, msg)', function(){6 var env7 before(function(){8 env = process.env.NODE_ENV9 })10 after(function(){11 process.env.NODE_ENV = env12 })137 var str = 'Hello CRC';8 var strUTF8 = '<!DOCTYPE html>\n<html>\n<head>\n</head>\n<body><p>自動販売</p></body></html>';14 it('should pass-through fn in test environment', function(){15 var fn = function(){}16 process.env.NODE_ENV = 'test'17 utils.deprecate(fn).should.equal(fn)18 })1920 it('should return new fn in other environment', function(){21 var fn = function(){}22 process.env.NODE_ENV = ''23 utils.deprecate(fn).should.not.equal(fn)24 })25})2627describe('utils.etag(body, encoding)', function(){28 it('should support strings', function(){11 utils.etag(str).should.eql('"-2034458343"');29 utils.etag('express!')30 .should.eql('"zZdv4imtWD49AHEviejT6A=="')31 })3233 it('should support utf8 strings', function(){15 utils.etag(strUTF8).should.eql('"1395090196"');34 utils.etag('express❤', 'utf8')35 .should.eql('"fsFba4IxwQS6h6Umb+FNxw=="')36 })3738 it('should support buffer', function(){19 utils.etag(new Buffer(strUTF8)).should.eql('"1395090196"');20 utils.etag(new Buffer(str)).should.eql('"-2034458343"');39 var buf = new Buffer('express!')40 utils.etag(buf)41 .should.eql('"zZdv4imtWD49AHEviejT6A=="');42 })4344 it('should support empty string', function(){45 utils.etag('')46 .should.eql('"1B2M2Y8AsgTpgAmY7PhCfg=="');47 })48})4950describe('utils.wetag(body, encoding)', function(){51 it('should support strings', function(){52 utils.wetag('express!')53 .should.eql('W/"8-3098196679"')54 })5556 it('should support utf8 strings', function(){57 utils.wetag('express❤', 'utf8')58 .should.eql('W/"a-1751845617"')59 })6061 it('should support buffer', function(){62 var buf = new Buffer('express!')63 utils.wetag(buf)64 .should.eql('W/"8-3098196679"');65 })6667 it('should support empty string', function(){68 utils.wetag('')69 .should.eql('W/"0-0"');70 })71})7273describe('utils.isAbsolute()', function(){74 it('should support windows', function(){75 assert(utils.isAbsolute('c:\\'));76 assert(!utils.isAbsolute(':\\'));77 })7831 it('should unices', function(){79 it('should support windows unc', function(){80 assert(utils.isAbsolute('\\\\foo\\bar'))81 })8283 it('should support unices', function(){84 assert(utils.isAbsolute('/foo/bar'));85 assert(!utils.isAbsolute('foo/bar'));86 })87})
8 unmodified lines
modified:History.md+35 added
1unreleased2==========34 * custom etag control with `app.set('etag', val)`5 - `app.set('etag', function(body, encoding){ return '"etag"' })` custom etag generation6 - `app.set('etag', 'weak')` weak tag7 - `app.set('etag', 'strong')` strong etag8 - `app.set('etag', false)` turn off9 - `app.set('etag', true)` standard etag10 * mark `res.send` ETag as weak and reduce collisions11 * update send to 0.4.012 - Calculate ETag with md5 for reduced collisions13 - Ignore stream errors after request ends14 - deps: debug@0.8.115164.3.2 / 2014-05-2817==================1819 * fix handling of errors from `router.param()` callbacks
118 unmodified lines
138 - `app.router()` - returns the app Router instance139 - `app.route()` - Proxy to the app's `Router#route()` method to create a new route140 - Router & Route - public API1411423.9.0 / 2014-05-30143==================144145 * custom etag control with `app.set('etag', val)`146 - `app.set('etag', function(body, encoding){ return '"etag"' })` custom etag generation147 - `app.set('etag', 'weak')` weak tag148 - `app.set('etag', 'strong')` strong etag149 - `app.set('etag', false)` turn off150 - `app.set('etag', true)` standard etag151 * Include ETag in HEAD requests152 * mark `res.send` ETag as weak and reduce collisions153 * update connect to 2.18.0154 - deps: compression@1.0.3155 - deps: serve-index@1.1.0156 - deps: serve-static@1.2.0157 * update send to 0.4.0158 - Calculate ETag with md5 for reduced collisions159 - Ignore stream errors after request ends160 - deps: debug@0.8.11611623.8.1 / 2014-05-27163==================164165 * update connect to 2.17.3
1354 unmodified lines
modified:package.json+5 added-5 removed
46 unmodified lines
47 "repository": "git://github.com/visionmedia/express",48 "license": "MIT",49 "dependencies": {50 "accepts": "1.0.1",51 "buffer-crc32": "0.2.1",52 "parseurl": "1.0.1",53 "proxy-addr": "1.0.0",54 "range-parser": "1.0.0",55 "send": "0.4.0",56 "type-is": "1.2.0",57 "cookie": "0.1.2",56 "buffer-crc32": "0.2.1",58 "fresh": "0.2.2",59 "methods": "1.0.0",59 "send": "0.3.0",60 "cookie-signature": "1.0.3",61 "merge-descriptors": "0.0.2",62 "utils-merge": "1.0.0",63 "escape-html": "1.0.1",
4 unmodified lines
68 },69 "devDependencies": {70 "after": "0.8.1",71 "istanbul": "0.2.10",72 "mocha": "~1.19.0",73 "should": "~3.3.1",72 "mocha": "~1.20.0",73 "should": "~4.0.0",74 "supertest": "~0.12.0",75 "connect-redis": "~2.0.0",76 "ejs": "~1.0.0",77 "jade": "~0.35.0",77 "jade": "~1.3.1",78 "marked": "0.3.2",79 "multiparty": "~3.2.4",80 "hjs": "~0.0.6",81 "body-parser": "1.2.2",
16 unmodified lines