Permalink
Browse files

refactor res.set() array support

  • Loading branch information...
1 parent 57cda15 commit a4b2e48dfea095f722a17b6b6d89e0a2ccee3fad @tj tj committed Jan 24, 2013
Showing with 7 additions and 4 deletions.
  1. +7 −4 lib/response.js
View
@@ -498,24 +498,27 @@ res.attachment = function(filename){
*
* Examples:
*
+ * res.set('Foo', ['bar', 'baz']);
* res.set('Accept', 'application/json');
* res.set({ Accept: 'text/plain', 'X-API-Key': 'tobi' });
*
* Aliased as `res.header()`.
*
- * @param {String|Object} field
+ * @param {String|Object|Array} field
* @param {String} val
* @return {ServerResponse} for chaining
* @api public
*/
res.set =
-res.header = function header(field, val){
+res.header = function(field, val){
if (2 == arguments.length) {
- this.setHeader(field, Array.isArray(val) ? val.map(String) : String(val));
+ if (Array.isArray(val)) val = val.map(String);
+ else val = String(val);
+ this.setHeader(field, val);
} else {
for (var key in field) {
- header.call(this, key, field[key]);
+ this.set(key, field[key]);
}
}
return this;

0 comments on commit a4b2e48

Please sign in to comment.