Skip to content
Myr

Changed `res.send(null)` responds with empty string

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

previously you would just get "null", which is fine for res.json() but probably not the best result for res.send()

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent 36e9c02 · Browse files · 2 files+12 added−4 removed
This commit

State

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

Diff stats

2 files+12 added−4 removed

  • tests:+8 added−0 removed
  • other:+4 added−4 removed

2 files+12 added−4 removed

modified:lib/response.js+4 added-4 removed
57 unmodified lines
58 }59 break;60 case 'boolean':61 case 'object':62 if (Buffer.isBuffer(body)) {63 if (!this.header('Content-Type')) {64 this.contentType('.bin');65 }62 if (null == body) {63 body = '';64 } else if (Buffer.isBuffer(body)) {65 if (!this.header('Content-Type')) this.contentType('.bin');66 } else {67 return this.json(body, status);68 }69 break;
338 unmodified lines
modified:test/response.test.js+8 added
93 unmodified lines
94 app.get('/204', function(req, res, next){95 res.send(204);96 });9798 app.get('/null', function(req, res, next){99 res.send(null);100 });101102 app.get('/undefined', function(req, res, next){103 res.send(undefined);104 });105
64 unmodified lines
170 assert.equal(undefined, res.headers['content-length']);171 });172173 assert.response(app,174 { url: '/null' },175 { body: '' });176177 assert.response(app,178 { url: '/undefined' },179 { body: '' });180 181 assert.response(app,
593 unmodified lines