Remove res.send(status) signature
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 · parent 0fc4f07 · Browse files · 6 files·+21 added−32 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+21 added−32 removed
- tests:+16 added−16 removed
- other:+5 added−16 removed
Provenance
- Commit
97ccc52- Tree
a67f315- Author
Douglas Christopher Wilson <doug@somethingdoug.com>- Committer
Douglas Christopher Wilson <doug@somethingdoug.com>- Parent
0fc4f07
6 files changed+21 added−32 removed
modified:examples/cors/index.js+2 added-2 removed
26 unmodified lines2728293031313233343536373839404141424344453 unmodified lines26 unmodified lines res.set('Access-Control-Allow-Origin', 'http://localhost:3000'); res.set('Access-Control-Allow-Methods', 'PUT'); res.set('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type'); // res.set('Access-Control-Allow-Max-Age', 3600); if ('OPTIONS' == req.method) return res.send(200); if ('OPTIONS' == req.method) return res.sendStatus(200); next();});
/** * PUT an existing user. */
api.put('/user/:id', function(req, res){ console.log(req.body); res.send(204); res.sendStatus(204);});
app.listen(3000);api.listen(3001);3 unmodified linesmodified:examples/search/index.js+2 added-2 removed
36 unmodified lines373839404141424344444546474816 unmodified lines36 unmodified lines/** * GET search for :query. */
app.get('/search/:query?', function(req, res){app.get('/search/:query?', function(req, res, next){ var query = req.params.query; db.smembers(query, function(err, vals){ if (err) return res.send(500); if (err) return next(err); res.send(vals); });});
16 unmodified linesmodified:lib/response.js-12 removed
94 unmodified lines95 this.statusCode = arguments[0];96 chunk = arguments[1];97 }98 99- // disambiguate res.send(status) and res.send(status, num)100- if (typeof chunk === 'number' && arguments.length === 1) {101- // res.send(status) will set status message as text string102- if (!this.get('Content-Type')) {103- this.type('txt');104- }105-106- deprecate('res.send(status): Use res.sendStatus(status) instead');107- this.statusCode = chunk;108- chunk = http.STATUS_CODES[chunk];109- }110-99 switch (typeof chunk) {100 // string defaulting to html101 case 'string':102 if (!this.get('Content-Type')) {767 unmodified linesmodified:test/app.routes.error.js+1 added-1 removed
30 unmodified lines313233343535363738394 unmodified lines30 unmodified lines a.should.be.false; b.should.be.true; c.should.be.true; d.should.be.false; res.send(204); res.sendStatus(204); });
request(app) .get('/')4 unmodified linesmodified:test/res.send.js+15 added-15 removed
34 unmodified lines35 });36 })37 })38 39- describe('.send(code)', function(){40- it('should set .statusCode', function(done){39+ describe('.send(code, body)', function(){40+ it('should set .statusCode and body', function(done){41 var app = express();42 43 app.use(function(req, res){44- res.send(201).should.equal(res);44+ res.send(201, 'Created :)');45 });46 47 request(app)48 .get('/')49- .expect('Created')49+ .expect('Created :)')50 .expect(201, done);51 })52 })53 54- describe('.send(code, body)', function(){55- it('should set .statusCode and body', function(done){54+ describe('.send(code, number)', function(){55+ it('should send number as json', function(done){56 var app = express();57 58 app.use(function(req, res){59- res.send(201, 'Created :)');59+ res.send(200, 0.123);60 });61 62 request(app)63 .get('/')64- .expect('Created :)')65- .expect(201, done);64+ .expect('Content-Type', 'application/json; charset=utf-8')65+ .expect(200, '0.123', done);66 })67 })68 69- describe('.send(code, number)', function(){70- it('should send number as json', function(done){69+ describe('.send(Number)', function(){70+ it('should send as application/json', function(done){71 var app = express();72 73 app.use(function(req, res){74- res.send(200, 0.123);74+ res.send(1000);75 });76 77 request(app)78 .get('/')79 .expect('Content-Type', 'application/json; charset=utf-8')80- .expect(200, '0.123', done);80+ .expect(200, '1000', done)81 })82 })83 84 describe('.send(String)', function(){313 unmodified lines398 var app = express();399 400 app.use(function(req, res){401 res.set('etag', '"asdf"');402- res.send(200);402+ res.send('hello!');403 });404 405 app.enable('etag');406 45 unmodified lines452 app.disable('etag');453 454 app.use(function(req, res){455 res.set('etag', '"asdf"');456- res.send(200);456+ res.send('hello!');457 });458 459 request(app)460 .get('/')78 unmodified linesmodified:History.md+1 added
7 unmodified lines8 - `req.acceptsLanguage` - use `req.acceptsLanguages`9 - `res.json(obj, status)` signature - use `res.json(status, obj)`10 - `res.jsonp(obj, status)` signature - use `res.jsonp(status, obj)`11 - `res.send(body, status)` signature - use `res.send(status, body)`12+ - `res.send(status)` signature - use `res.sendStatus(status)`13 - `res.sendfile` - use `res.sendFile` instead14 - `express.query` middleware15 * change:16 - `req.host` now returns host (`hostname:port`) - use `req.hostname` for only hostname2454 unmodified lines