Skip to content
Myr

Merge branch 'set-cookie'

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 · parents ab38124, cb7e7b2 · Browse files · 1 file+30 added−5 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+30 added−5 removed

  • other:+30 added−5 removed

1 file+30 added−5 removed

modified:lib/express/response.js+30 added-5 removed
15 unmodified lines
16 mime = require('connect/utils').mime,17 Buffer = require('buffer').Buffer;1819/**20 * Header fields supporting multiple values.21 * 22 * @type Array23 */2425var multiple = ['Set-Cookie'];2627/**28 * Send a response with the given `body` and optional `headers` and `status` code.29 *30 * Examples:31 *
19 unmodified lines
51 }5253 // Defaults54 status = status || 200;47 headers = headers || {};5556 // Determine content type57 switch (typeof body) {58 case 'number':
28 unmodified lines
87 : Buffer.byteLength(body));88 }8990 // Merge headers passed84 utils.merge(this.headers, headers);91 if (headers) {92 var fields = Object.keys(headers);93 for (var i = 0, len = fields.length; i < len; ++i) {94 var field = fields[i];95 this.header(field, headers[field]);96 }97 }9899 // Respond100 this.writeHead(status, this.headers);101 this.end(body);
80 unmodified lines
182183/**184 * Set or get response header `name` with optional `val`.185 *186 * Headers that may be set multiple times (as indicated by the `multiple` array)187 * can be called with a value several times, for example:188 *189 * res.header('Set-Cookie', '...');190 * res.header('Set-Cookie', '...');191 *192 * @param {String} name193 * @param {String} val194 * @return {String}195 * @api public196 */197198http.ServerResponse.prototype.header = function(name, val){180 return val === undefined181 ? this.headers[name]182 : this.headers[name] = val;199 if (val === undefined) {200 return this.headers[name];201 } else {202 if (this.headers[name] && ~multiple.indexOf(name)) {203 return this.headers[name] += '\r\n' + name + ': ' + val;204 } else {205 return this.headers[name] = val;206 }207 }208};209210/**211 * Redirect to the given `url` with optional response `status`
60 unmodified lines