Refactored req/res proto assignments
Before adoption: this commit came in with the history the project adopted, so no landing records it.
since the names may change in the near future (is suspect at least) due to inconsistancies
authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent 6a03a92 · Browse files · 2 files·+21 added−19 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+21 added−19 removed
- other:+21 added−19 removed
Provenance
- Commit
99820e7- Tree
f402656- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
6a03a92
2 files changed+21 added−19 removed
modified:lib/request.js+9 added-8 removed
9 unmodified lines10 */11 12 var http = require('http')13 , utils = require('./utils')14- , mime = require('connect').utils.mime;14+ , mime = require('connect').utils.mime15+ , req = http.IncomingMessage.prototype;16 17 /**18 * Default flash formatters.19 *28 unmodified lines48 * @return {String} 49 * @api public50 */51 51-http.IncomingMessage.prototype.header = function(name, defaultValue){52+req.header = function(name, defaultValue){53 return this.headers[name.toLowerCase()] || defaultValue;54 };55 56 /**25 unmodified lines82 * @return {Boolean}83 * @api public84 */85 85-http.IncomingMessage.prototype.accepts = function(type){86+req.accepts = function(type){87 var accept = this.header('Accept');88 89 // Normalize extensions ".json" -> "json"90 if (type && '.' == type[0]) type = type.substr(1);34 unmodified lines125 * @return {String}126 * @api public127 */128 128-http.IncomingMessage.prototype.param = function(name, defaultValue){129+req.param = function(name, defaultValue){130 // Route params like /user/:id131 if (this.params[name] !== undefined) {132 return this.params[name]; 133 }42 unmodified lines176 * @return {Array|Object|Number}177 * @api public178 */179 179-http.IncomingMessage.prototype.flash = function(type, msg){180+req.flash = function(type, msg){181 var msgs = this.session.flash = this.session.flash || {};182 if (type && msg) {183 var i = 2184 , args = arguments58 unmodified lines243 * @return {Boolean}244 * @api public245 */246 246-http.IncomingMessage.prototype.is = function(type){247+req.is = function(type){248 var fn = this.app.is(type);249 if (fn) return fn(this);250 var contentType = this.headers['content-type'];251 if (!contentType) return;21 unmodified lines273 * @return {Boolean}274 * @api public275 */276 276-http.IncomingMessage.prototype.__defineGetter__('isXMLHttpRequest', isxhr);277-http.IncomingMessage.prototype.__defineGetter__('xhr', isxhr);277+req.__defineGetter__('isXMLHttpRequest', isxhr);278+req.__defineGetter__('xhr', isxhr);modified:lib/response.js+12 added-11 removed
13 unmodified lines14 , path = require('path')15 , pump = require('sys').pump16 , utils = require('connect').utils17 , parseRange = require('./utils').parseRange18- , mime = utils.mime;18+ , mime = utils.mime19+ , res = http.ServerResponse.prototype;20 21 /**22 * Header fields supporting multiple values.23 * 21 unmodified lines45 * @return {ServerResponse}46 * @api public47 */48 48-http.ServerResponse.prototype.send = function(body, headers, status){49+res.send = function(body, headers, status){50 // Allow status as second arg51 if (typeof headers === 'number') {52 status = headers,53 headers = null;75 unmodified lines129 * @param {Function} fn130 * @api public131 */132 132-http.ServerResponse.prototype.sendfile = function(path, fn){133+res.sendfile = function(path, fn){134 var self = this135 , ranges = self.req.headers.range136 , head = 'HEAD' == self.req.method;137 64 unmodified lines202 * @return {String} the resolved mime type203 * @api public204 */205 205-http.ServerResponse.prototype.contentType = function(type){206+res.contentType = function(type){207 if (!~type.indexOf('.')) type = '.' + type;208 return this.header('Content-Type', mime.type(type));209 };210 4 unmodified lines215 * @return {ServerResponse}216 * @api public217 */218 218-http.ServerResponse.prototype.attachment = function(filename){219+res.attachment = function(filename){220 this.header('Content-Disposition', filename221 ? 'attachment; filename="' + path.basename(filename) + '"'222 : 'attachment');223 return this;10 unmodified lines234 * @return {Type}235 * @api public236 */237 237-http.ServerResponse.prototype.download = function(path, filename, fn){238+res.download = function(path, filename, fn){239 this.attachment(filename || path).sendfile(path, fn);240 };241 242 /**10 unmodified lines253 * @return {String}254 * @api public255 */256 256-http.ServerResponse.prototype.header = function(name, val){257+res.header = function(name, val){258 if (val === undefined) {259 return this.headers[name];260 } else {261 return ~multiple.indexOf(name)8 unmodified lines270 * @param {String} name271 * @api public272 */273 273-http.ServerResponse.prototype.clearCookie = function(name){274+res.clearCookie = function(name){275 this.cookie(name, '', { expires: new Date(1) });276 };277 278 /**9 unmodified lines288 * @param {Options} options289 * @api public290 */291 291-http.ServerResponse.prototype.cookie = function(name, val, options){292+res.cookie = function(name, val, options){293 var cookie = utils.serializeCookie(name, val, options);294 this.header('Set-Cookie', cookie);295 };296 37 unmodified lines334 * @param {Number} code335 * @api public336 */337 337-http.ServerResponse.prototype.redirect = function(url, status){338+res.redirect = function(url, status){339 var basePath = this.app.set('home') || '/'340 , status = status || 302341 , body;342 36 unmodified lines379 * @return {Mixed} val380 * @api public381 */382 382-http.ServerResponse.prototype.local = function(name, val){383+res.local = function(name, val){384 this.locals = this.locals || {};385 return undefined === val386 ? this.locals[name]387 : this.locals[name] = val;2 unmodified lines