Skip to content
Myr

add res.vary(). Closes #1682

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

authored by cjihrig · committed by TJ Holowaychuk · parent e43ff07 · Browse files · 2 files+94 added−1 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+94 added−1 removed

  • tests:+55 added−0 removed
  • other:+39 added−1 removed

2 files+94 added−1 removed

modified:lib/response.js+39 added-1 removed
461 unmodified lines
462 var keys = Object.keys(obj);463464 var key = req.accepts(keys);465466 this.set('Vary', 'Accept');466 this.vary("Accept");467468 if (key) {469 this.set('Content-Type', normalizeType(key).value);470 obj[key](req, this, next);
249 unmodified lines
720 this.end(head ? null : body);721};722723/**724 * Add `field` to Vary. If already present in the Vary set, then725 * this call is simply ignored.726 *727 * @param {Array|String} field728 * @param {ServerResponse} for chaining729 * @api public730 */731732res.vary = function(field){733 var self = this;734735 // nothing736 if (!field) return this;737738 // array739 if (Array.isArray(field)) {740 field.forEach(function(field){741 self.vary(field);742 });743 return;744 }745746 var vary = this.get('Vary');747748 // append 749 if (vary) {750 vary = vary.split(/ *, */);751 if (!~vary.indexOf(field)) vary.push(field);752 this.set('Vary', vary.join(', '));753 return this;754 }755756 // set757 this.set('Vary', field);758 return this;759};760761/**762 * Render `view` with the given `options` and optional callback `fn`.763 * When a callback function is given a response will _not_ be made764 * automatically, otherwise a response of _200_ and _text/html_ is given.765 *
34 unmodified lines
added:test/res.vary.js+55 added