Skip to content
Myr

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

2 files+21 added−19 removed

modified:lib/request.js+9 added-8 removed
9 unmodified lines
10 */1112var http = require('http')13 , utils = require('./utils')14 , mime = require('connect').utils.mime;14 , mime = require('connect').utils.mime15 , req = http.IncomingMessage.prototype;1617/**18 * Default flash formatters.19 *
28 unmodified lines
48 * @return {String} 49 * @api public50 */5151http.IncomingMessage.prototype.header = function(name, defaultValue){52req.header = function(name, defaultValue){53 return this.headers[name.toLowerCase()] || defaultValue;54};5556/**
25 unmodified lines
82 * @return {Boolean}83 * @api public84 */8585http.IncomingMessage.prototype.accepts = function(type){86req.accepts = function(type){87 var accept = this.header('Accept');8889 // Normalize extensions ".json" -> "json"90 if (type && '.' == type[0]) type = type.substr(1);
34 unmodified lines
125 * @return {String}126 * @api public127 */128128http.IncomingMessage.prototype.param = function(name, defaultValue){129req.param = function(name, defaultValue){130 // Route params like /user/:id131 if (this.params[name] !== undefined) {132 return this.params[name]; 133 }
42 unmodified lines
176 * @return {Array|Object|Number}177 * @api public178 */179179http.IncomingMessage.prototype.flash = function(type, msg){180req.flash = function(type, msg){181 var msgs = this.session.flash = this.session.flash || {};182 if (type && msg) {183 var i = 2184 , args = arguments
58 unmodified lines
243 * @return {Boolean}244 * @api public245 */246246http.IncomingMessage.prototype.is = function(type){247req.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 lines
273 * @return {Boolean}274 * @api public275 */276276http.IncomingMessage.prototype.__defineGetter__('isXMLHttpRequest', isxhr);277http.IncomingMessage.prototype.__defineGetter__('xhr', isxhr);277req.__defineGetter__('isXMLHttpRequest', isxhr);278req.__defineGetter__('xhr', isxhr);
modified:lib/response.js+12 added-11 removed
13 unmodified lines
14 , 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;2021/**22 * Header fields supporting multiple values.23 *
21 unmodified lines
45 * @return {ServerResponse}46 * @api public47 */4848http.ServerResponse.prototype.send = function(body, headers, status){49res.send = function(body, headers, status){50 // Allow status as second arg51 if (typeof headers === 'number') {52 status = headers,53 headers = null;
75 unmodified lines
129 * @param {Function} fn130 * @api public131 */132132http.ServerResponse.prototype.sendfile = function(path, fn){133res.sendfile = function(path, fn){134 var self = this135 , ranges = self.req.headers.range136 , head = 'HEAD' == self.req.method;137
64 unmodified lines
202 * @return {String} the resolved mime type203 * @api public204 */205205http.ServerResponse.prototype.contentType = function(type){206res.contentType = function(type){207 if (!~type.indexOf('.')) type = '.' + type;208 return this.header('Content-Type', mime.type(type));209};210
4 unmodified lines
215 * @return {ServerResponse}216 * @api public217 */218218http.ServerResponse.prototype.attachment = function(filename){219res.attachment = function(filename){220 this.header('Content-Disposition', filename221 ? 'attachment; filename="' + path.basename(filename) + '"'222 : 'attachment');223 return this;
10 unmodified lines
234 * @return {Type}235 * @api public236 */237237http.ServerResponse.prototype.download = function(path, filename, fn){238res.download = function(path, filename, fn){239 this.attachment(filename || path).sendfile(path, fn);240};241242/**
10 unmodified lines
253 * @return {String}254 * @api public255 */256256http.ServerResponse.prototype.header = function(name, val){257res.header = function(name, val){258 if (val === undefined) {259 return this.headers[name];260 } else {261 return ~multiple.indexOf(name)
8 unmodified lines
270 * @param {String} name271 * @api public272 */273273http.ServerResponse.prototype.clearCookie = function(name){274res.clearCookie = function(name){275 this.cookie(name, '', { expires: new Date(1) });276};277278/**
9 unmodified lines
288 * @param {Options} options289 * @api public290 */291291http.ServerResponse.prototype.cookie = function(name, val, options){292res.cookie = function(name, val, options){293 var cookie = utils.serializeCookie(name, val, options);294 this.header('Set-Cookie', cookie);295};296
37 unmodified lines
334 * @param {Number} code335 * @api public336 */337337http.ServerResponse.prototype.redirect = function(url, status){338res.redirect = function(url, status){339 var basePath = this.app.set('home') || '/'340 , status = status || 302341 , body;342
36 unmodified lines
379 * @return {Mixed} val380 * @api public381 */382382http.ServerResponse.prototype.local = function(name, val){383res.local = function(name, val){384 this.locals = this.locals || {};385 return undefined === val386 ? this.locals[name]387 : this.locals[name] = val;
2 unmodified lines