Skip to content
Myr

refactor res.set() array support

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 57cda15 · Browse files · 1 file+7 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

1 file+7 added−4 removed

  • other:+7 added−4 removed

1 file+7 added−4 removed

modified:lib/response.js+7 added-4 removed
496 unmodified lines
497 * an object of header fields.498 *499 * Examples:500 *501 * res.set('Foo', ['bar', 'baz']);502 * res.set('Accept', 'application/json');503 * res.set({ Accept: 'text/plain', 'X-API-Key': 'tobi' });504 *505 * Aliased as `res.header()`.506 *506 * @param {String|Object} field507 * @param {String|Object|Array} field508 * @param {String} val509 * @return {ServerResponse} for chaining510 * @api public511 */512513res.set =513res.header = function header(field, val){514res.header = function(field, val){515 if (2 == arguments.length) {515 this.setHeader(field, Array.isArray(val) ? val.map(String) : String(val));516 if (Array.isArray(val)) val = val.map(String);517 else val = String(val);518 this.setHeader(field, val);519 } else {520 for (var key in field) {518 header.call(this, key, field[key]);521 this.set(key, field[key]);522 }523 }524 return this;525};
229 unmodified lines