Skip to content
Myr

Added `.default()` support to `res.format()`

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

authored by TJ Holowaychuk · committed by TJ Holowaychuk · parent c145ab9 · Browse files · 2 files+31 added−8 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+31 added−8 removed

  • tests:+18 added−0 removed
  • other:+13 added−8 removed

2 files+31 added−8 removed

modified:lib/response.js+13 added-8 removed
345 unmodified lines
346 *347 * By default Express passes an `Error`348 * with a `.status` of 406 to `next(err)`349 * if a match is not made, however you may350 * provide an optional callback `fn` to350 * provide a `.default` callback to351 * be invoked instead.352 *353 * @param {Object} obj354 * @param {Function} fn354 * @return {ServerResponse} for chaining355 * @api public356 */357359res.format = function(obj, fn){358res.format = function(obj){359 var keys = Object.keys(obj)360 , req = this.req362 , next = req.next363 , key = req.accepts(keys);361 , next = req.next;362363 var fn = obj.default;364 if (fn) delete obj.default;365366 var key = req.accepts(keys);367368 this.set('Vary', 'Accept');369370 if (key) {371 this.set('Content-Type', normalizeType(key));
195 unmodified lines
567 },568569 html: function(){570 body = '<p>' + statusCodes[status] + '. Redirecting to <a href="' + url + '">' + url + '</a></p>';571 },572573 default: function(){574 body = '';575 }569 }, function(){570 body = '';571 })576 });577578 // Respond579 this.statusCode = status;580 this.set('Location', url);
74 unmodified lines
modified:test/res.format.js+18 added