Merge tag '3.6.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 bc9bcb0, f7be983 · Browse files · 13 files·+242 added−18 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
13 files+242 added−18 removed
- tests:+144 added−7 removed
- other:+98 added−11 removed
Provenance
- Commit
35c5060- Tree
1078394- Author
Douglas Christopher Wilson <doug@somethingdoug.com>- Committer
Douglas Christopher Wilson <doug@somethingdoug.com>- Parent 1
bc9bcb0- Parent 2
f7be983
13 files changed+242 added−18 removed
modified:examples/resource/app.js+1 added-1 removed
15 unmodified lines1617181920202122232466 unmodified lines15 unmodified lines var format = req.params.format; obj.range(req, res, a, b, format); }); this.get(path + '/:id', obj.show); this.del(path + '/:id', obj.destroy); this.delete(path + '/:id', obj.destroy);};
// Fake records
66 unmodified linesmodified:examples/route-map/index.js+4 added-4 removed
32 unmodified lines333435363737383940414243444546474748495051525354555556575859606161626364653 unmodified lines32 unmodified lines get: function(req, res){ res.send('user ' + req.params.uid); },
del: function(req, res){ delete: function(req, res){ res.send('delete users'); }};
var pets = { list: function(req, res){ res.send('user ' + req.params.uid + '\'s pets'); },
del: function(req, res){ delete: function(req, res){ res.send('delete ' + req.params.uid + '\'s pet ' + req.params.pid); }};
app.map({ '/users': { get: users.list, del: users.del, delete: users.delete, '/:uid': { get: users.get, '/pets': { get: pets.list, '/:pid': { del: pets.del delete: pets.delete } } } }3 unmodified linesmodified:examples/route-middleware/index.js+1 added-1 removed
75 unmodified lines76 app.get('/user/:id/edit', loadUser, andRestrictToSelf, function(req, res){77 res.send('Editing user ' + req.user.name);78 });79 80-app.del('/user/:id', loadUser, andRestrictTo('admin'), function(req, res){80+app.delete('/user/:id', loadUser, andRestrictTo('admin'), function(req, res){81 res.send('Deleted user ' + req.user.name);82 });83 84 app.listen(3000);1 unmodified linemodified:lib/application.js+2 added-1 removed
9 unmodified lines10 var query = require('./middleware/query');11 var debug = require('debug')('express:application');12 var View = require('./view');13 var http = require('http');14+var deprecate = require('./utils').deprecate;15 16 /**17 * Application prototype.18 */413 unmodified lines432 };433 434 // del -> delete alias435 435-app.del = app.delete;436+app.del = deprecate(app.delete, 'app.del: Use app.delete instead');437 438 /**439 * Render the given view `name` name with `options`440 * and a callback accepting an error and the93 unmodified linesmodified:lib/response.js+19 added
8 unmodified lines9 var sign = require('cookie-signature').sign;10 var normalizeType = require('./utils').normalizeType;11 var normalizeTypes = require('./utils').normalizeTypes;12 var contentDisposition = require('./utils').contentDisposition;13+var deprecate = require('./utils').deprecate;14 var etag = require('./utils').etag;15 var statusCodes = http.STATUS_CODES;16 var cookie = require('cookie');17 var send = require('send');156 unmodified lines174 if (2 == arguments.length) {175 // res.json(body, status) backwards compat176 if ('number' == typeof arguments[1]) {177 this.statusCode = arguments[1];178+ return 'number' === typeof obj179+ ? jsonNumDeprecated.call(this, obj)180+ : jsonDeprecated.call(this, obj);181 } else {182 this.statusCode = obj;183 obj = arguments[1];184 }10 unmodified lines195 196 return this.send(body);197 };198 199+var jsonDeprecated = deprecate(res.json,200+ 'res.json(obj, status): Use res.json(status, obj) instead');201+202+var jsonNumDeprecated = deprecate(res.json,203+ 'res.json(num, status): Use res.status(status).json(num) instead');204+205 /**206 * Send JSON response with JSONP callback support.207 *208 * Examples:14 unmodified lines223 if (2 == arguments.length) {224 // res.json(body, status) backwards compat225 if ('number' == typeof arguments[1]) {226 this.statusCode = arguments[1];227+ return 'number' === typeof obj228+ ? jsonpNumDeprecated.call(this, obj)229+ : jsonpDeprecated.call(this, obj);230 } else {231 this.statusCode = obj;232 obj = arguments[1];233 }25 unmodified lines259 260 return this.send(body);261 };262 263+var jsonpDeprecated = deprecate(res.json,264+ 'res.jsonp(obj, status): Use res.jsonp(status, obj) instead');265+266+var jsonpNumDeprecated = deprecate(res.json,267+ 'res.jsonp(num, status): Use res.status(status).jsonp(num) instead');268+269 /**270 * Transfer the file at the given `path`.271 *272 * Automatically sets the _Content-Type_ response header field.531 unmodified linesmodified:lib/utils.js+16 added
3 unmodified lines4 5 var mime = require('send').mime;6 var crc32 = require('buffer-crc32');7 var basename = require('path').basename;8+var deprecate = require('util').deprecate;9 10 /**11+ * Deprecate function, like core `util.deprecate`12+ *13+ * @param {Function} fn14+ * @param {String} msg15+ * @return {Function}16+ * @api private17+ */18+19+exports.deprecate = function(fn, msg){20+ return 'test' !== process.env.NODE_ENV21+ ? deprecate(fn, 'express: ' + msg)22+ : fn;23+};24+25+/**26 * Return ETag for `body`.27 *28 * @param {String|Buffer} body29 * @return {String}121 unmodified linesmodified:test/app.router.js+1 added-2 removed
4 unmodified lines5 , methods = require('methods');6 7 describe('app.router', function(){8 describe('methods supported', function(){9- methods.forEach(function(method){9+ methods.concat('del').forEach(function(method){10 if (method === 'connect') return;11 12 it('should include ' + method.toUpperCase(), function(done){13- if (method == 'delete') method = 'del';13 var app = express();14 var calls = [];15 16 app[method]('/foo', function(req, res){579 unmodified linesmodified:test/res.format.js+22 added-4 removed
2 unmodified lines3 , request = require('supertest')4 , utils = require('../lib/utils')5 , assert = require('assert');6 7-var app = express();7+var app1 = express();8 9-app.use(function(req, res, next){9+app1.use(function(req, res, next){10 res.format({11 'text/plain': function(){12 res.send('hey');13 },10 unmodified lines24 }25 });26 });27 28-app.use(function(err, req, res, next){28+app1.use(function(err, req, res, next){29 if (!err.types) throw err;30 res.send(err.status, 'Supports: ' + err.types.join(', '));31 })32 19 unmodified lines52 default: function(){ res.send('default') }53 })54 });55 56+var app4 = express();57+58+app4.get('/', function(req, res, next){59+ res.format({60+ text: function(){ res.send('hey') },61+ html: function(){ res.send('<p>hey</p>') },62+ json: function(){ res.send({ message: 'hey' }) }63+ });64+});65+66+app4.use(function(err, req, res, next){67+ res.send(err.status, 'Supports: ' + err.types.join(', '));68+})69+70 describe('res', function(){71 describe('.format(obj)', function(){72 describe('with canonicalized mime types', function(){59- test(app);73+ test(app1);74 })75 76 describe('with extnames', function(){77 test(app2);8 unmodified lines86 })87 })88 89 describe('in router', function(){90+ test(app4);91+ })92+93+ describe('in router', function(){94 var app = express();95 var router = express.Router();96 97 router.get('/', function(req, res, next){83 unmodified linesmodified:test/res.json.js+52 added-1 removed
30 unmodified lines31 .expect(200, '{"hello":"world"}', done);32 })33 34 describe('when given primitives', function(){35- it('should respond with json', function(done){35+ it('should respond with json for null', function(done){36 var app = express();37 38 app.use(function(req, res){39 res.json(null);6 unmodified lines46 res.text.should.equal('null');47 done();48 })49 })50+51+ it('should respond with json for Number', function(done){52+ var app = express();53+54+ app.use(function(req, res){55+ res.json(300);56+ });57+58+ request(app)59+ .get('/')60+ .end(function(err, res){61+ res.statusCode.should.equal(200);62+ res.headers.should.have.property('content-type', 'application/json');63+ res.text.should.equal('300');64+ done();65+ })66+ })67+68+ it('should respond with json for String', function(done){69+ var app = express();70+71+ app.use(function(req, res){72+ res.json('str');73+ });74+75+ request(app)76+ .get('/')77+ .end(function(err, res){78+ res.statusCode.should.equal(200);79+ res.headers.should.have.property('content-type', 'application/json');80+ res.text.should.equal('"str"');81+ done();82+ })83+ })84 })85 86 describe('when given an array', function(){87 it('should respond with json', function(done){114 unmodified lines202 res.text.should.equal('{"id":1}');203 done();204 })205 })206+207+ it('should use status as second number for backwards compat', function(done){208+ var app = express();209+210+ app.use(function(req, res){211+ res.json(200, 201);212+ });213+214+ request(app)215+ .get('/')216+ .end(function(err, res){217+ res.statusCode.should.equal(201);218+ res.headers.should.have.property('content-type', 'application/json');219+ res.text.should.equal('200');220+ done();221+ })222+ })223 })224 })modified:test/res.jsonp.js+69 added
199 unmodified lines200 })201 })202 })203 204+ describe('when given primitives', function(){205+ it('should respond with json for null', function(done){206+ var app = express();207+208+ app.use(function(req, res){209+ res.jsonp(null);210+ });211+212+ request(app)213+ .get('/')214+ .end(function(err, res){215+ res.headers.should.have.property('content-type', 'application/json');216+ res.text.should.equal('null');217+ done();218+ })219+ })220+221+ it('should respond with json for Number', function(done){222+ var app = express();223+224+ app.use(function(req, res){225+ res.jsonp(300);226+ });227+228+ request(app)229+ .get('/')230+ .end(function(err, res){231+ res.statusCode.should.equal(200);232+ res.headers.should.have.property('content-type', 'application/json');233+ res.text.should.equal('300');234+ done();235+ })236+ })237+238+ it('should respond with json for String', function(done){239+ var app = express();240+241+ app.use(function(req, res){242+ res.jsonp('str');243+ });244+245+ request(app)246+ .get('/')247+ .end(function(err, res){248+ res.statusCode.should.equal(200);249+ res.headers.should.have.property('content-type', 'application/json');250+ res.text.should.equal('"str"');251+ done();252+ })253+ })254+ })255+256 describe('"json replacer" setting', function(){257 it('should be passed to JSON.stringify()', function(done){258 var app = express();259 76 unmodified lines336 res.text.should.equal('{"id":1}');337 done();338 })339 })340+341+ it('should use status as second number for backwards compat', function(done){342+ var app = express();343+344+ app.use(function(req, res){345+ res.jsonp(200, 201);346+ });347+348+ request(app)349+ .get('/')350+ .end(function(err, res){351+ res.statusCode.should.equal(201);352+ res.headers.should.have.property('content-type', 'application/json');353+ res.text.should.equal('200');354+ done();355+ })356+ })357 })358 })modified:History.md+47 added
1 4.2.x2 =====3 4+ * deprecate `app.del()` -- use `app.delete()` instead5+ * deprecate `res.json(obj, status)` -- use `res.json(status, obj)` instead6+ - the edge-case `res.json(status, num)` requires `res.status(status).json(num)`7+ * deprecate `res.jsonp(obj, status)` -- use `res.jsonp(status, obj)` instead8+ - the edge-case `res.jsonp(status, num)` requires `res.status(status).jsonp(num)`9 * fix `req.next` when inside router instance10 * include `ETag` header in `HEAD` requests11 * keep previous `Content-Type` for `res.jsonp`12+ * support PURGE method13+ - add `app.purge`14+ - add `router.purge`15+ - include PURGE in `app.all`16+ * update debug to 0.8.017+ - add `enable()` method18+ - change from stderr to stdout19+ * update methods to 1.0.020+ - add PURGE21 22 4.1.2 / 2014-05-0823 ==================24 68 unmodified lines93 - `app.router()` - returns the app Router instance94 - `app.route()` - Proxy to the app's `Router#route()` method to create a new route95 - Router & Route - public API96 97+3.6.0 / 2014-05-0998+==================99+100+ * deprecate `app.del()` -- use `app.delete()` instead101+ * deprecate `res.json(obj, status)` -- use `res.json(status, obj)` instead102+ - the edge-case `res.json(status, num)` requires `res.status(status).json(num)`103+ * deprecate `res.jsonp(obj, status)` -- use `res.jsonp(status, obj)` instead104+ - the edge-case `res.jsonp(status, num)` requires `res.status(status).jsonp(num)`105+ * support PURGE method106+ - add `app.purge`107+ - add `router.purge`108+ - include PURGE in `app.all`109+ * update connect to 2.15.0110+ * Add `res.appendHeader`111+ * Call error stack even when response has been sent112+ * Patch `res.headerSent` to return Boolean113+ * Patch `res.headersSent` for node.js 0.8114+ * Prevent default 404 handler after response sent115+ * dep: compression@1.0.2116+ * dep: connect-timeout@1.1.0117+ * dep: debug@^0.8.0118+ * dep: errorhandler@1.0.1119+ * dep: express-session@1.0.4120+ * dep: morgan@1.0.1121+ * dep: serve-favicon@2.0.0122+ * dep: serve-index@1.0.2123+ * update debug to 0.8.0124+ * add `enable()` method125+ * change from stderr to stdout126+ * update methods to 1.0.0127+ - add PURGE128+ * update mkdirp to 0.5.0129+130 3.5.3 / 2014-05-08131 ==================132 133 * fix `req.host` for IPv6 literals1279 unmodified linesmodified:package.json+7 added-3 removed
15 unmodified lines16 "name": "Ciaran Jessup",17 "email": "ciaranj@gmail.com"18 },19 {20+ "name": "Douglas Christopher Wilson",21+ "email": "doug@somethingdoug.com"22+ },23+ {24 "name": "Guillermo Rauch",25 "email": "rauchg@gmail.com"26 },27 {12 unmodified lines40 "range-parser": "1.0.0",41 "cookie": "0.1.2",42 "buffer-crc32": "0.2.1",43 "fresh": "0.2.2",40- "methods": "0.1.0",44+ "methods": "1.0.0",45 "send": "0.3.0",46 "cookie-signature": "1.0.3",47 "merge-descriptors": "0.0.2",48 "utils-merge": "1.0.0",49 "escape-html": "1.0.1",50 "qs": "0.6.6",51 "serve-static": "1.1.0",52 "path-to-regexp": "0.1.2",49- "debug": ">= 0.7.3 < 1"53+ "debug": ">= 0.8.0 < 1"54 },55 "devDependencies": {56 "mocha": "~1.18.2",57 "body-parser": "1.0.2",3 unmodified lines61 "marked": "0.3.2",62 "multiparty": "~3.2.4",63 "hjs": "~0.0.6",64 "should": "~3.3.1",61- "supertest": "~0.11.0",65+ "supertest": "~0.12.0",66 "method-override": "1.0.0",67 "cookie-parser": "1.0.1",68 "express-session": "1.0.4",69 "morgan": "1.0.1",23 unmodified linesmodified:Readme.md+1 added-1 removed
1 [](http://expressjs.com/)2 3 Fast, unopinionated, minimalist web framework for [node](http://nodejs.org).4 5- [](https://travis-ci.org/visionmedia/express) [](https://www.gittip.com/visionmedia/)5+ [](https://travis-ci.org/visionmedia/express) [](https://www.gittip.com/visionmedia/) [](http://badge.fury.io/js/express)6 7 ```js8 var express = require('express');9 var app = express();99 unmodified lines