Skip to content
Myr

deprecate res.json(obj, status)

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

closes #2106 closes #2107

authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parent 0461e55 · Browse files · 4 files+57 added−0 removed
This commit

State

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

Diff stats

4 files+57 added−0 removed

  • tests:+34 added−0 removed
  • other:+23 added−0 removed

4 files+57 added−0 removed

modified:lib/response.js+19 added
7 unmodified lines
8 , utils = connect.utils9 , sign = require('cookie-signature').sign10 , normalizeType = require('./utils').normalizeType11 , normalizeTypes = require('./utils').normalizeTypes12 , deprecate = require('./utils').deprecate13 , etag = require('./utils').etag14 , statusCodes = http.STATUS_CODES15 , cookie = require('cookie')16 , send = require('send')
160 unmodified lines
177 if (2 == arguments.length) {178 // res.json(body, status) backwards compat179 if ('number' == typeof arguments[1]) {180 this.statusCode = arguments[1];181 return 'number' === typeof obj182 ? jsonNumDeprecated.call(this, obj)183 : jsonDeprecated.call(this, obj);184 } else {185 this.statusCode = obj;186 obj = arguments[1];187 }
11 unmodified lines
199200 return this.send(body);201};202203var jsonDeprecated = deprecate(res.json,204 'res.json(obj, status): Use res.json(status, obj) instead');205206var jsonNumDeprecated = deprecate(res.json,207 'res.json(num, status): Use res.status(status).json(num) instead');208209/**210 * Send JSON response with JSONP callback support.211 *212 * Examples:
14 unmodified lines
227 if (2 == arguments.length) {228 // res.json(body, status) backwards compat229 if ('number' == typeof arguments[1]) {230 this.statusCode = arguments[1];231 return 'number' === typeof obj232 ? jsonpNumDeprecated.call(this, obj)233 : jsonpDeprecated.call(this, obj);234 } else {235 this.statusCode = obj;236 obj = arguments[1];237 }
26 unmodified lines
264265 return this.send(body);266};267268var jsonpDeprecated = deprecate(res.json,269 'res.jsonp(obj, status): Use res.jsonp(status, obj) instead');270271var jsonpNumDeprecated = deprecate(res.json,272 'res.jsonp(num, status): Use res.status(status).jsonp(num) instead');273274/**275 * Transfer the file at the given `path`.276 *277 * Automatically sets the _Content-Type_ response header field.
545 unmodified lines
modified:test/res.json.js+17 added
modified:test/res.jsonp.js+17 added
262 unmodified lines
263 res.text.should.equal('{"id":1}');264 done();265 })266 })267268 it('should use status as second number for backwards compat', function(done){269 var app = express();270271 app.use(function(req, res){272 res.jsonp(200, 201);273 });274275 request(app)276 .get('/')277 .end(function(err, res){278 res.statusCode.should.equal(201);279 res.headers.should.have.property('content-type', 'application/json; charset=utf-8');280 res.text.should.equal('200');281 done();282 })283 })284 })285})
modified:History.md+4 added
13.x2===34 * 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 * update connect to 2.15.010 * Add `res.appendHeader`11 * Call error stack even when response has been sent12 * Patch `res.headerSent` to return Boolean
1298 unmodified lines