Skip to content
Myr

patch.js

This file

Path

lib/patch.js

54 lines · 1.2 KiB · JavaScript

Last changed by

move support for multiple `res.cookie` calls to lib/responseRoman Shtylmanbefore adoptiond42d8f5

History of this file

Take it

remove last pieces of connect dependencyRoman Shtylmanbefore adoption1396e08

lines 1–32why, one step back
1/*!
2 * Connect3 * Copyright(c) 2011 TJ Holowaychuk4 * MIT Licensed5 */67/**8 * Module dependencies.9 */1011var http = require('http');12var ServerResponse = http.ServerResponse;1314// apply only once15if (ServerResponse.prototype._hasConnectPatch) {16 return;17}1819// original methods20var setHeader = ServerResponse.prototype.setHeader;21var writeHead = ServerResponse.prototype.writeHead;2223/**24 * Set header `field` to `val`, special-casing25 * the `Set-Cookie` field for multiple support.26 *27 * @param {String} field28 * @param {String} val29 * @api public30 */3132ServerResponse.prototype.setHeader = function(field, val){

move support for multiple `res.cookie` calls to lib/responseRoman Shtylmanbefore adoptiond42d8f5

line 33why, one step back
33 var key = field.toLowerCase();

remove last pieces of connect dependencyRoman Shtylmanbefore adoption1396e08

line 34why, one step back
34

move support for multiple `res.cookie` calls to lib/responseRoman Shtylmanbefore adoptiond42d8f5

line 35why, one step back
35 if ('content-type' == key && this.charset) {

remove last pieces of connect dependencyRoman Shtylmanbefore adoption1396e08

lines 36–54why, one step back
36 val += '; charset=' + this.charset;
37 }3839 return setHeader.call(this, field, val);40};4142ServerResponse.prototype.writeHead = function(statusCode, reasonPhrase, headers){43 if (typeof reasonPhrase === 'object') headers = reasonPhrase;44 if (typeof headers === 'object') {45 Object.keys(headers).forEach(function(key){46 this.setHeader(key, headers[key]);47 }, this);48 }49 if (!this._emittedHeader) this.emit('header');50 this._emittedHeader = true;51 return writeHead.call(this, statusCode, reasonPhrase);52};5354ServerResponse.prototype._hasConnectPatch = true;