Skip to content

Commit

Permalink
fix: make getter properties enumerable
Browse files Browse the repository at this point in the history
  • Loading branch information
teclone committed Nov 29, 2018
1 parent d74b299 commit e341896
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions src/modules/Request.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,31 @@
*@module Request
*/

import Util from './Util';
import {IncomingMessage as Request} from 'http';

const proto = Request.prototype;
Object.defineProperties(Request.prototype, {
/**
*@type {boolean}
*@memberof Request#
*/
isHttps: {
configurable: true,
get() {
return this.connection.encrypted;
}
},

/**
*@type {boolean}
*@name isHttps
*@memberof Request#
*/
Util.defineGetter(proto, 'isHttps', function() {
return this.connection.encrypted;
});

/**
*@type {string}
*@name hostname
*@memberof Request#
*/
Util.defineGetter(proto, 'hostname', function() {
const host = this.headers['host'];
return typeof host === 'string'? host.replace(/:\d+$/, '') : '';
/**
*@type {string}
*@memberof Request#
*/
hostname: {
configurable: true,
get() {
const host = this.headers['host'];
return typeof host === 'string'? host.replace(/:\d+$/, '') : '';
}
}
});

export default Request;

0 comments on commit e341896

Please sign in to comment.