Skip to content
Myr

Fix res.send(status, num) to send num as json

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

fixes #2226

authored by Yad Smood · committed by Douglas Christopher Wilson · parent cf8005e · Browse files · 3 files+25 added−6 removed
This commit

State

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

Diff stats

3 files+25 added−6 removed

  • tests:+15 added−0 removed
  • other:+10 added−6 removed

3 files+25 added−6 removed

modified:lib/response.js+9 added-6 removed
101 unmodified lines
102 body = arguments[1];103 }104 }105106 // disambiguate res.send(status) and res.send(status, num)107 if (typeof body === 'number' && arguments.length === 1) {108 // res.send(status) will set status message as text string109 this.get('Content-Type') || this.type('txt');110 this.statusCode = body;111 body = http.STATUS_CODES[body];112 }113114 switch (typeof body) {107 // response status108 case 'number':109 this.get('Content-Type') || this.type('txt');110 this.statusCode = body;111 body = http.STATUS_CODES[body];112 break;115 // string defaulting to html116 case 'string':117 if (!this.get('Content-Type')) {118 this.charset = this.charset || 'utf-8';119 this.type('html');120 }121 break;122 case 'boolean':123 case 'number':124 case 'object':125 if (null == body) {126 body = '';127 } else if (Buffer.isBuffer(body)) {
689 unmodified lines
modified:test/res.send.js+15 added
75 unmodified lines
76 .expect(400, done);77 })78 })7980 describe('.send(code, number)', function(){81 it('should send number as json', function(done){82 var app = express();8384 app.use(function(req, res){85 res.send(200, 0.123);86 });8788 request(app)89 .get('/')90 .expect('Content-Type', 'application/json; charset=utf-8')91 .expect(200, '0.123', done);92 })93 })9495 describe('.send(String)', function(){96 it('should send as html', function(done){97 var app = express();98
447 unmodified lines
modified:History.md+1 added
13.x2===34 * fix `res.send(status, num)` to send `num` as json (not error)5 * deps: basic-auth@1.0.06 - support empty password7 - support empty username8 * deps: connect@2.23.0
1520 unmodified lines