Skip to content
Myr

Replace __defineGetter__ with Object.defineProperty

Before adoption: this commit came in with the history the project adopted, so no landing records it.

closes #2162

authored by Guy Ellis Monster · committed by Douglas Christopher Wilson · parent bdfd288 · Browse files · 1 file+26 added−10 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+26 added−10 removed

  • other:+26 added−10 removed

1 file+26 added−10 removed

modified:lib/request.js+26 added-10 removed
247 unmodified lines
248 * @return {String}249 * @api public250 */251252req.__defineGetter__('protocol', function(){252defineGetter(req, 'protocol', function protocol(){253 var trust = this.app.get('trust proxy fn');254255 if (!trust(this.connection.remoteAddress)) {256 return this.connection.encrypted
15 unmodified lines
272 * @return {Boolean}273 * @api public274 */275276req.__defineGetter__('secure', function(){276defineGetter(req, 'secure', function secure(){277 return 'https' == this.protocol;278});279280/**
5 unmodified lines
286 * @return {String}287 * @api public288 */289290req.__defineGetter__('ip', function(){290defineGetter(req, 'ip', function ip(){291 var trust = this.app.get('trust proxy fn');292 return proxyaddr(this, trust);293});294
8 unmodified lines
303 * @return {Array}304 * @api public305 */306307req.__defineGetter__('ips', function(){307defineGetter(req, 'ips', function ips() {308 var trust = this.app.get('trust proxy fn');309 var addrs = proxyaddr.all(this, trust);310 return addrs.slice(1).reverse();311});
12 unmodified lines
324 * @return {Array}325 * @api public326 */327328req.__defineGetter__('subdomains', function(){328defineGetter(req, 'subdomains', function subdomains() {329 var offset = this.app.get('subdomain offset');330 return (this.host || '')331 .split('.')332 .reverse()
6 unmodified lines
339 * @return {String}340 * @api public341 */342343req.__defineGetter__('path', function(){343defineGetter(req, 'path', function path() {344 return parse(this).pathname;345});346347/**
6 unmodified lines
354 * @return {String}355 * @api public356 */357358req.__defineGetter__('host', function(){358defineGetter(req, 'host', function host(){359 var trust = this.app.get('trust proxy fn');360 var host = this.get('X-Forwarded-Host');361362 if (!host || !trust(this.connection.remoteAddress)) {
21 unmodified lines
384 * @return {Boolean}385 * @api public386 */387388req.__defineGetter__('fresh', function(){388defineGetter(req, 'fresh', function(){389 var method = this.method;390 var s = this.res.statusCode;391392 // GET or HEAD for weak freshness validation only
15 unmodified lines
408 * @return {Boolean}409 * @api public410 */411412req.__defineGetter__('stale', function(){412defineGetter(req, 'stale', function stale(){413 return !this.fresh;414});415416/**
2 unmodified lines
419 * @return {Boolean}420 * @api public421 */422423req.__defineGetter__('xhr', function(){423defineGetter(req, 'xhr', function xhr(){424 var val = this.get('X-Requested-With') || '';425 return 'xmlhttprequest' == val.toLowerCase();426});427428/**429 * Helper function for creating a getter on an object.430 *431 * @param {Object} obj432 * @param {String} name433 * @param {Function} getter434 * @api private435 */436function defineGetter(obj, name, getter) {437 Object.defineProperty(obj, name, {438 configurable: true,439 enumerable: true,440 get: getter441 });442};