]> git.cworth.org Git - obsolete/notmuch-web/blob - node_modules/express/node_modules/connect/lib/patch.js
Install the "express" node module via npm
[obsolete/notmuch-web] / node_modules / express / node_modules / connect / lib / patch.js
1
2 /*!
3  * Connect
4  * Copyright(c) 2011 TJ Holowaychuk
5  * MIT Licensed
6  */
7
8 /**
9  * Module dependencies.
10  */
11
12 var http = require('http')
13   , res = http.OutgoingMessage.prototype;
14
15 // original setHeader()
16
17 var setHeader = res.setHeader;
18
19 /**
20  * Set header `field` to `val`, special-casing
21  * the `Set-Cookie` field for multiple support.
22  *
23  * @param {String} field
24  * @param {String} val
25  * @api public
26  */
27
28 res.setHeader = function(field, val){
29   var key = field.toLowerCase()
30     , prev;
31
32   // special-case Set-Cookie
33   if (this._headers && 'set-cookie' == key) {
34     if (prev = this.getHeader(field)) {
35       val = Array.isArray(prev)
36         ? prev.concat(val)
37         : [prev, val];
38     }
39   // charset
40   } else if ('content-type' == key && this.charset) {
41     val += '; charset=' + this.charset;
42   }
43
44   return setHeader.call(this, field, val);
45 };